add id to html element javascript code example Example: set attribute javascript Element.setAttribute(name, value);