jQuery next() 应该很简单,但不起作用
我正在尝试做看起来应该是一个简单的 jQuery 效果,我以前使用过类似的代码,但我无法让它工作。我对此还很陌生,这可能是非常简单的事情,但我花了很长时间,我没有看到它。
我的 hmtl 是这样的
<a href="#" class="trigger">details</a>
<div class="details">
<?echo $data['referral'];?>
<a href="#">update</a>
</div>
我的 jQuery
$(document).ready(function () {
$('.trigger').click(function() {
$(this).nextAll(".details:first").toggle('slow', function () {
});
});
});
我也尝试过: $(this).next().toggle('slow', function ()
唯一有效的是 $('.details').toggle('慢', function () 但这会打开我页面上的所有详细信息选项卡,不是很有用。
非常感谢任何提示!
I am trying to do what seems like should be a simple jQuery effect, I've used similar code before, but I am unable to get it to work. I am still pretty new to this, it's probably something super easy, but I have spent quite some time, I don't see it.
My hmtl is like this
<a href="#" class="trigger">details</a>
<div class="details">
<?echo $data['referral'];?>
<a href="#">update</a>
</div>
My jQuery
$(document).ready(function () {
$('.trigger').click(function() {
$(this).nextAll(".details:first").toggle('slow', function () {
});
});
});
I have also tried:
$(this).next().toggle('slow', function ()
The only thing that will work is
$('.details').toggle('slow', function ()
but that opens all the details tabs on my page, not very useful.
Would greatly appreciate any tips!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常感谢您的回答!我的问题似乎确实是使用 Codeigniter 的结果,我的 a 和 div 标签周围有空格,当我在 firebug 中查看生成的 html 时,正如 Patrick 建议的那样,空格被包含在 p 标签中,而 p 标签不在我的代码,例如:
所以我必须使用类似parent().next().child()的东西。我删除了空白,元素再次成为兄弟姐妹,一切都很好。现在我需要弄清楚如何阻止 codeigniter 这样做!
再次感谢!
丽贝卡
Thank you so much for the answers! My problem did seem to be the result of using Codeigniter, I had white space around my a and div tags, and when I looked at the generated html in firebug, as Patrick suggested, the white space was encased in p tags that were not in my code, like:
So I would have had to use something like parent().next().child(). I removed the white space, and the elements became siblings again and all is well. Now I need to figure out how to stop codeigniter from doing that!
Thanks again!
Rebecca