javascript - Why can't I set "style" directly -
let's suppose have <div>. set style color:red.
<div style="color:red">text</div> why can't set style through javascript so:
document.getelementsbytagname("div")[0].style="color:blue"; but can set property of style:
document.getelementsbytagname("div")[0].style.color="blue";
this dom model. js debug tool use? run in browser console:
document.getelementsbytagname("div")[0].style this result:

so, command returned object. this:
document.getelementsbytagname("div")[0].style="color:blue"; you redefining object. not correct @ all.
that's , can't it.
if want have tool manage css properties better can use jquery: prop() function
Comments
Post a Comment