changing the id of an element in jquery?
i want to change the id of an element in jquery i.e
$('.aiButton').click(function(){
$('.aiButton').id('saveold');
<a class="aiButton" id="savenew" href="login.php"><span>Save</span></a开发者_JS百科></li>
you see i want to chnage the id from savenew to saveold
is this how you do it, i think this is worng thanks!!
To set the ID, you need $('.aiButton').attr('id', 'saveold');
, or more efficiently in this case this.id = 'saveold'
.
I do this:
$('.aiButton').click(function()
{
// $(this).removeAttr('id');
$(this).attr('id', 'id-name-goes-here');
});
精彩评论