I am new to jQuery and would like to update an element’s id. My approach is:
-
select this element by its id
-
overwrite this id with a new value.
would you mind telling me where my mistake is?
Thanks!
Below is the HTML code:
<tr><th><label for="id_aerial_size_dist">Aerial size dist:</label></th><td><select name="aerial_size_dist" id="id_aerial_size_dist">
<option value="a">Very Fine to Fine</option>
<option value="b">Fine to Medium (EFED Default)</option>
<option value="c">Medium to Coarse</option>
<option value="d">Coarse to Very Coarse</option>
</select></td></tr>
jquery
<script type="text/javascript" src=" ../stylesheets/jQuery-1.7.2.js"></script>
<script>
$(document).ready(function() {
$('#id_aerial_size_dist').attr('id', 'id_a');
});
</script>
Yes there is a way to change any attribute.
Then again, this is definitely not recommended and it is also a pretty bad practice. You can however use classes for the same functionality.
If you tell me what you need to do I will help you out with a solution.