To set an attribute in JavaScript, do this:
element.setAttribute('some-attribute', 'some-value')
.For example, if this is your element:
<div id="my-element">text</div>
And you set an attribute like so:
document.getElementById('my-element').setAttribute('class', 'marked');
The result will be:
<div id="my-element" class="marked">text</div>