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:

enter image description here

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

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -