html - javascript object : current or method? -
this code:
var x = document.getelementbyid("x");
this html:
<p id="x">text</p>
this next javascript:
x.innerhtml = "newtext" alert(x.innerhtml)
so happen? x
save information when using
var x = document.getelementbyid("x")
, variablex
change not html<p>
idx
?
since x reference dom element, it'd modify innerhtml of id - x.
demo: jsfiddle
var x = document.getelementbyid("x"); x.innerhtml = "newtext"; alert(x.innerhtml); //same below alert alert (document.getelementbyid("x").innerhtml);
Comments
Post a Comment