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();
}
精彩评论