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.

  1.  
  2. <div id="my_test_id">
  3.      WOOOOOOOOOOOOW
  4. </div>
  5.  
  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: http://api.jquery.com/attr/
– Clone: http://api.jquery.com/clone/

Leave a Reply

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