jQuery 仅在父 div 中切换具有类的元素
这两天我一直在用头撞桌子。我正在制作一个应用程序,显示来自数据库的信息、标题/链接、缩略图和保存在无序列表中的时间,如下所示: http://blog.madebycraig.com/images/full.jpg
我想做的是在元素上有一个最小化按钮,打开和关闭缩略图和保存时间: http://blog.madebycraig.com/images/minimized.jpg
我可以做到这一点,但要么全有要么全无。我单击一个最小化按钮,然后一切就完成了。我怎样才能包含它来只切换具有特定类名的项目,这些项目是最小化按钮所在的 div 的子项?我尝试过 .parent()、.child()、.next()、.prev()。我已经把我所知道的一切都扔给它了。现在我转向你们,善良的先生(或女士)。我做错了什么?这是我试图运行它的 ul。
echo'
<li class="bookmarkContainer">
<a href="'.$row['url'].'" class="toggle"><img class="thumb" src="images/placeholder.png" /></a>
<div class="title"><a href="'.$row['url'].'" class="bookmrk" target="_blank">'.$row['title'].'</a></div>
<div class="dt toggle">'.relativeTime($row['dt']).'</div><br />
<a class="collapse" href="#">hide</a>
<a class="delete" href="?delete='.$row['id'].'" id="'.$row['id'].'">Delete Bookmark</a>
</li>';
I've been beating my head against my desk for the last two days over this one. I'm making an app that displays info from a db, the title/link, thumbnail, and time saved wrapped in an unordered list, like so: http://blog.madebycraig.com/images/full.jpg
What I'm trying to do is have a minimize button on the element, toggling the thumbnail and time saved on and off: http://blog.madebycraig.com/images/minimized.jpg
I can accomplish this, but it's all or nothing. I click one minimize button, and everything goes. How can I contain it to just toggle items with a certain class name that are children of the div that the minimize button is in? I've tried .parent(), .child(), .next(), .prev(). I've thrown everything at it that I know. Now I turn to you, kind sirs (or madams). What am I doing wrong? Here's the ul I'm trying to run it on.
echo'
<li class="bookmarkContainer">
<a href="'.$row['url'].'" class="toggle"><img class="thumb" src="images/placeholder.png" /></a>
<div class="title"><a href="'.$row['url'].'" class="bookmrk" target="_blank">'.$row['title'].'</a></div>
<div class="dt toggle">'.relativeTime($row['dt']).'</div><br />
<a class="collapse" href="#">hide</a>
<a class="delete" href="?delete='.$row['id'].'" id="'.$row['id'].'">Delete Bookmark</a>
</li>';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
.closest()
和.find()
像这样:如果你有很多这些,或者它们正在改变通过ajax(似乎是搜索结果的东西),使用
.live()
< /a> 或.delegate()
像这样:You can do it using
.closest()
and.find()
like this:If you have lots of these, or they are changing via ajax (seems like a search-resulty thing), use
.live()
or.delegate()
like this: