开发者

changing the id of an element in jquery?

开发者 https://www.devze.com 2023-02-01 11:24 出处:网络
i want to change the id of an element in jquery i.e $(\'.aiButton\').click(function(){ $(\'.aiButton\').id(\'saveold\');

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

精彩评论

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

关注公众号