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") , variable x change not html <p> id x?

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

Popular posts from this blog

rest - Spring boot: Request method 'PUT' not supported -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

symfony - imagine_filter() not generating the correct url in LiipImagineBundle -