开发者

Change a buttons id on click

开发者 https://www.devze.com 2023-02-24 03:05 出处:网络
I need to change the id attribute of a div on click. <div class=\"xtra\" id=\"id1\"><a href=\"#\"><span>Next</span></a></div>

I need to change the id attribute of a div on click.

<div class="xtra" id="id1"><a href="#"><span>Next</span></a></div> 

How would I do t开发者_开发技巧hat?

I've tried:

$j("#id1").attr('id', 'id2');

but that didn't work.


try this:

$j("#id1").live('click',function(){
      $(this).attr('id', 'id2'); //use this one
      this.id = 'id2'; //or this one <-- they both do the same thing
})

I am not sure why you would ever want to do this, that is how you would do it.

IDs are not meant to change, they are meant to be unique to a specific element.

Classes are usually used when changing css back and forth.

0

精彩评论

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