Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the value of id or name?

Tags:

javascript

Example:

<table id ='table'>
<tr>
<td>1</td>
<td><select id='old' name='old'></select></td>
<td><select id='old2' name='old2'></select></td>
<td><div id='old3' name='old3'></div></td>
</tr>
</table>

How to change the value of id or name from select id ='old' to select id ='new' (for example) after deleting rows in javascript? I have been trying all the methods like trying getElementById('old') = 'new' but not work, used replaceChild also not work (or maybe I put the wrong code, no idea). Do you have other alternatives? (No JQuery, please).

Thanks.

like image 399
candies Avatar asked Dec 11 '25 21:12

candies


1 Answers

You can use the setAttribute method to accomplish this

document.getElementById("old").setAttribute("id","new");
document.getElementById("new").setAttribute("name","new");
like image 74
Malitta N Avatar answered Dec 15 '25 21:12

Malitta N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!