javascript - .innerHTML vs. createElement() | setAttribute() vs. Direct* -


i told not "proper", did not worry until started getting run-time error in ie9. here code need converted use object properties. why innerhtml not considered best practice?

  var c=document.createelement('div');   c.innerhtml= '<a name="a1" class="b" href="' + d[2].value + '">' + d[1].value + '</a>'; 

it's strange you're putting a element inside a element below should work.

var c=document.createelement('a'); c.name = "a1"; c.classname = "b"; c.href = d[2].value; c.appendchild(document.createtextnode(d[1].value)); 

this assumes d[1].value not known formed html trusted source more robust against xss innerhtml code.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -