开发者

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');
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜