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
Post a Comment