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
3
4
5
6
7
8
 
<div id="my_test_id">
     WOOOOOOOOOOOOW
</div>
 
<script type='text/javascript'>
     $('#my_test_id').attr('id', 'my_new_id');
</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