Add css class to a javascript event -


how can add class following element?

window.location = 'page.html'; 

for example, i'd result:

<a href="page.html" class="nameclass">link</a> 

but javascript page loads automatically after function, not link text click on.

create link element:

var = document.createelement('a'); // <a></a> 

add href:

a.href = 'page.html'; // <a href="page.html"></a> 

add class:

a.classname = 'nameclass'; // <a href="page.html" class="nameclass"></a> 

add text:

a.innerhtml = 'link'; // <a href="page.html" class="nameclass">link</a> 

append body element:

document.body.appendchild(a); // in page! 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -