开发者

What's wrong with this $(this).attr("id").toggle("");

What is the proper syntax for toggling the this.id obj开发者_运维百科ect

$(this).attr("id").toggle("");

Thanks. Google is surprisingly not helping :(


The reason it is not working is that your first

$(this).attr("id")

Returns a string, the ID of your item. What you probably want is:

$(this).toggle();


toggle() is only used for showing/hiding an element, so your question is not entirely clear.

If you want to remove the id, you could use:

$(this).attr("id","");

Or maybe you want to toggle an element with a specific id:

 $("#myid").toggle();


This will look for DIVs with any ID attribute and toggle on click:

$('div[id]').click(function() {
   $(this).toggle();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜