最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - changing the id of an element in jquery? - Stack Overflow

programmeradmin7浏览0评论

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></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!!

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></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!!

Share Improve this question asked Dec 29, 2010 at 19:09 getawaygetaway 8,99023 gold badges66 silver badges96 bronze badges 2
  • There isn't an id() function. – BoltClock Commented Dec 29, 2010 at 19:12
  • 2 He mentioned i.e. not literally. – MacMac Commented Dec 29, 2010 at 19:16
Add a ment  | 

2 Answers 2

Reset to default 7

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)

  1. 暂无评论