Javascript 如何更改slideToggle上的标题和html
我有以下HTML标记:Javascript 如何更改slideToggle上的标题和html,javascript,jquery,Javascript,Jquery,我有以下HTML标记: <a title="Hide comments" hreflang="1" class="comment-show-link" rel="tooltip" href="">Hide comments</a> <a title="Hide comments" hreflang="2" class="comment-show-link" rel="tooltip" href="">Hide comments</a> 但不知道如
<a title="Hide comments" hreflang="1" class="comment-show-link" rel="tooltip" href="">Hide comments</a>
<a title="Hide comments" hreflang="2" class="comment-show-link" rel="tooltip" href="">Hide comments</a>
但不知道如何检查DIV是否隐藏或可见,以及在每种情况下更改标题和HTML。我还知道我可以使用text()或html()jQuery函数来实现这一点,但是如何实现呢?有什么帮助吗
提前感谢试试这个:
$('.comment-show-link').click(function(e) {
var $this = $(this);
var num = $this.attr('hreflang');
$('#comment-show-'+num).slideToggle('slow', function(){
if ($(this).is(':hidden')) {
// do something here
// $this.attr('...', '...')
}
});
e.preventDefault();
});
见和。要了解某些jQuery方法是如何工作的,请阅读它们的文档:,。很好,这很有效!感谢积分并接受答案归你@undefinedone最后一个问题,我试图更改HTML,但页面中的每个元素都会更改。我只想更改我单击的元素。这是我使用的代码:怎么了?@ReynierPM你的代码没有问题,你有多个ID相同的元素吗?
$('.comment-show-link').click(function(e) {
var $this = $(this);
var num = $this.attr('hreflang');
$('#comment-show-'+num).slideToggle('slow', function(){
if ($(this).is(':hidden')) {
// do something here
// $this.attr('...', '...')
}
});
e.preventDefault();
});