How to Reset ID of an Element – jQuery

Hey All,

Just a quick post on how to set the ID of an element (in this case a div) with jQuery. I needed to use this to dynamically clone elements.

  2. <div id="my_test_id">
  4. </div>
  6. <script type='text/javascript'>
  7.      $('#my_test_id').attr('id', 'my_new_id');
  8. </script>

The script above sets the id of div to my_new_id. If you’re interested, there’s a whole heap of documentation on the jquery site:
– Attr:
– Clone:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.