css - javascript how to select elements and style it -


may know how build css style parser/evaluator in javascript below:

.book { width: calc(200px + 400px); } .book h1 { font-size: 10em; } div.book { color: blue; } .book.green { background: green; } .book[name="hello"] { color: pink; } .book[data-name="hi"], .other-book { color: red; } .book > { text-decoration: none; } .book a:nth-child(2) { color: purple; } 

document.getelementsbyclassname('box') returns collection. should specify specific index inside square brackets this

document.getelementsbyclassname('box')[0].style.width = '100px'; 

this has difference between classes , ids. there can multiple elements same class name, ids unique. same formula as

document.getelementbyid 

does not work classes, because of difference mentioned above.

although, best done through css.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -