单击时更改按钮ID

时间:2011-04-11 23:14:05

标签: jquery jquery-selectors

我需要在点击时更改id的{​​{1}}属性。

div

我该怎么做?

我试过了:

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

但这没效果。

1 个答案:

答案 0 :(得分:4)

试试这个:

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

我不确定你为什么要这样做,这就是你要做的。

ID无意更改,它们对于特定元素而言是唯一的。

通常在来回更换css时使用类。

相关问题