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

Popular posts from this blog

Linux vanilla kernel on QEMU and networking with eth0 -

rdbms - what exactly the undo information lives in oracle? -

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -