dom - How to modify style to a link in JavaScript? -


how can make text in div (the content of variable name) become link? in other words: change style "a" without using jquery.

var newtit=document.createelement('div'); newtit.id=name; // name variable newtit.innerhtml= name;  document.getelementbyid("w3c").appendchild(newtit); 

just did div, instead of creating div, create anchor element. add link want href-attribute.

var newtit=document.createelement('a'); newtit.href = "http://www.google.com" newtit.innerhtml= "linkylink";  document.getelementbyid("w3c").appendchild(newtit); 

based on content, first create div append anchor element it

var tab = document.createelement("div"); tab.id = "tabx"; document.getelementbyid("w3c").appendchild("tab");  var link = document.createelement("a"); link.href = "#tabx"; link.innertext = "tab xx"; document.getelementbyid("tabx").appendchild("tab"); 

or write anchor straight inner html

tab.innerhtml = "<a href='#tabx'>tab xx</a>" 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -