Javascript Inner HTML with HTML Tags -
i'm working on project school , wanted create javscript function adds text html element onclick method run function.
function a(func, words){ var initfunc = "<span class = 'link' onclick='" + string(func) +"();'>" + words + "</span>"; return t.innerhtml += initfunc; } the issue when page ran function, html presented has tags acting part of string, not acting html tags.
string(func) won't give name of function.
for that, can use func.name, defined in es6 draft, work if function global.
better use dom methods if want add event listeners:
function a(func, words){ var span = document.createelement('span'); span.classname = 'link'; span.onclick = func; span.appendchild(document.createtextnode(words)); t.appendchild(span); }
Comments
Post a Comment