开发者

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

开发者 https://www.devze.com 2022-12-13 16:42 出处:网络
What is the proper syntax for toggling the this.id obj开发者_运维百科ect $(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

精彩评论

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