[英]How do I use jQuery slideToggle on multiple elements?
I need the "Call link" to open the drawer for each item using slideToggle
, however the .next
method doesn't seem to be finding the class
. 我需要“调用链接”以使用
slideToggle
打开每个项目的抽屉,但是.next
方法似乎找不到class
。 Is my syntax incorrect? 我的语法不正确吗? Any help would be MUCH appreciated :D
任何帮助将不胜感激:D
Cheers! 干杯!
HTML HTML
<article class='tile'>
<h2>Lorem Ipsum</h2>
<p>Get international support.</p>
<ul>
<li><a class='call' style="background-image: url(img/icon_call.png);" href='#'>Call us</a></li>
<li><a id='chat' style="background-image: url(img/icon_chat.png);" href='#'>Live Chat</a></li>
</ul>
</article>
<span class='med_div'></span>
<section class='drawer'>
<a href='tel:' class='block_item'><span class='title pull-left'>Wireless</span><span class='number pull-right'>770-5566</span></a>
<a href='tel:' class='block_item'><span class='title pull-left'>GoPhone®</span><span class='number pull-right'>770-5566</span></a>
<a href='tel:' class='block_item'><span class='title pull-left'>Wireless Home Phone</span><span class='number pull-right'>770-5566</span></a>
</section>
<article class='tile'>
<h2>Lorem Ipsum</h2>
<p>Get international support.</p>
<ul>
<li><a class='call' style="background-image: url(img/icon_call.png);" href='#'>Call us</a></li>
<li><a id='chat' style="background-image: url(img/icon_chat.png);" href='#'>Live Chat</a></li>
</ul>
</article>
<span class='med_div'></span>
<section class='drawer'>
<a href='tel:' class='block_item'><span class='title pull-left'>Wireless</span><span class='number pull-right'>770-5566</span></a>
<a href='tel:' class='block_item'><span class='title pull-left'>GoPhone®</span><span class='number pull-right'>770-5566</span></a>
<a href='tel:' class='block_item'><span class='title pull-left'>Wireless Home Phone</span><span class='number pull-right'>770-5566</span></a>
</section>
JS JS
<script>
$(document).ready(function(){
$('.call').click(function() {
$('this').next('.drawer').slideToggle('slow', function() {
});
});
});
</script>
There are multiple problems in your code 您的代码中存在多个问题
this
is a object reference not a string this
是一个对象引用而不是字符串 .drawer
is a next().next()
sibling of the clicked .call
elements parent .tile
.drawer
是next().next()
所点击的兄弟.call
元素的父.tile
you have to use 你必须使用
$('.call').click(function() {
$(this).closest('.tile').next().next('.drawer').slideToggle('slow', function() {
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.