How to set new id attribute with jQuery?

To implement this, extract id from attr() and use replace() to replace the id attribute.

Example

Following is the code −



   
   
   Document





   

To run the above program, save the file name “anyName.html(index.html)”. Right click on the file and select the option “Open with Live Server” in VS Code editor.

Output

This will produce the following output −

Following is the value on console −

Updated on: 2020-11-09T10:49:58+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements