YouTip LogoYouTip

Js Htmldom Css

# JavaScript HTML DOM - Changing CSS * * * HTML DOM allows JavaScript to change the styles of HTML elements. * * * ## Changing HTML Styles To change the style of an HTML element, use this syntax: document.getElementById(_id_).style._property_=_new style_ The following example changes the style of a

element: ## Example

Hello World!

Hello World!

document.getElementById("p2").style.color="blue"; document.getElementById("p2").style.fontFamily="Arial"; document.getElementById("p2").style.fontSize="larger";

The paragraphs above were modified by script.

[Try it Β»](#) * * * ## Using Events HTML DOM allows us to execute code by triggering events. For example, the following events: * An element is clicked. * The page has finished loading. * An input field has been modified. * ... In the following chapters, you will learn more about events. This example changes the style of the HTML element with id="id1" when the user clicks the button: ## Example

My Heading 1

[Try it Β»](#) * * * ## More Examples (#) How to make an element invisible. Do you want the element to be shown or hidden?
← Js Htmldom EventsJs Htmldom Html β†’