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

android - Automated my builds -

python - How to return the most similar word from a list of words? -

php - Iterate over object properties with keys from second array -