我是今天早上的一个jQuery新手,这是我想出的代码,用于显示一个div,它伴随着调用它的锚点,在一个带有’foo’类的div中.它不起作用:P $('div.foo').children('a').click(function(event){ event.preventDe
$('div.foo').children('a').click(function(event){
event.preventDefault();
if ($(this).closest('div').('div').is(':hidden')) {
$(this).closest('div').('div').show("slow");
} else {
$(this).closest('div').('div').hide("slow");
}
});
HTML:
<div class="foo">
<a href="#" title="">Click me!</a>
<div>And this will appear!</div>
</div>
我希望能够有多个相同的foo div(当然除了嵌套div的实际内容之外),我需要做的就是将包含div的’foo’类赋予它以使得包含的锚显示出来单击时包含div.
这种事情甚至可能吗?在此先感谢您的回复.
试试这个$('div.foo a').click(function(event){
event.preventDefault();
$(this).next().toggle('slow');
});
