Javascript – DOM API access and change the style and content of an HTML element

Javascript – DOM API access and change the style and content of an HTML element

DOM (Document Object Model) can be used to modify HTML elements and CSS styles on the fly. The DOM API is accessible through the document property. Access HTML elements querySelector(selector) – returns the first element querySelectAll(selector) – returns a collection of HTML elements getElementById(id) – same as querySelector() getElementByTagName(tag) getElementsByClassName() Change the style If you want to modify the style on an element, you have to use the style attribute. Then change the CSS property by removing – and make capital the next letter. Exampes: text-align => textAlign / style.textAlign…

Javascript – DOM API access and change the style and content of an HTML element Read More