html - which one is given more preference for JavaScript or CSS? -


here code

<!doctype html> <html> <head>     <style>         body {             color:red;         }     </style>     <script>         window.onclick = function(){             document.getelementsbytagname("body").color="blue";         }     </script> </head> <body>     here text test </body> 

when run in browser (initially red) , click in window doesn't respond click mean should change color of text red blue nothing happens. wrong?

try this:-

demo

this add style attribute body element, override css rule.

window.onclick = function(){         document.getelementsbytagname("body")[0].style.color="blue";     } 

it should style.color color property of style property of element , though body .getelementsbytagname returns collection need use document.getelementsbytagname("body")[0] element , apply style it.

and yes styles applied element direclty override class css rule


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -