0

I want to set new id to div using its old Id?

$("#oldId").attr("id","newId");

Its not working.

Asmita
  • 1,160
  • 3
  • 10
  • 31

3 Answers3

0

simple JS

document.getElementById("PreviousName").id="CurrentName";
polin
  • 2,745
  • 2
  • 15
  • 20
0

Your code will work fine, though as of jQuery 1.6 you are encouraged to use prop over attr (see here for discussion).

$(function() {
    $('#test').prop('id', 'test2');
    $('#test2').fadeOut(3000);
});

Fiddle here

Community
  • 1
  • 1
Elliott
  • 2,669
  • 2
  • 23
  • 33
0

Take a look at this question. Can I change the ID of an HTML element using Javascript? Make sure you re-execute your jquery function after the change. Maybe you're working on a 'cached' javascript-object, not the DOM object.

Community
  • 1
  • 1
Andries
  • 1,547
  • 10
  • 29