2010-01-25 164 views
1

HTML:更改标签(jQuery的)

<a href="#">Show next element</a> 
<div>content</div> 

的jQuery:

$('a').toggle(function() { 
    $(this).next().show(); 
}, 
function() { 
    $(this).next().hide(); 
}); 

如何更改jQuery的上方,它也是在链接改变 “显示”“隐藏“元素是否可见?

谢谢!

回答

1

尚未经过测试...

$('a').toggle(function() { 
    $(this).next().show(); 
    $(this).html("Hide next element"); 
}, 
function() { 
    $(this).next().hide(); 
    $(this).html("Show next element"); 
}); 
+0

我想这一个秒前。 .text()更好,不过谢谢! – 3zzy 2010-01-25 06:06:23

+1

伟大的思想家都认为:D – alex 2010-01-25 06:06:30

+0

@Nimbuz .text()仅当您不包括HTML时。 – alex 2010-01-25 06:07:07

0
$('a').toggle(function() { 

    $(this).next().show(); 
    $(this).html('Hide next element'); 
}, 
function() { 
    $(this).next().hide(); 
    $(this).html('Show next element'); 
});