Html DOM: Difference between revisions

From wikinotes
No edit summary
Line 12: Line 12:
= Examples =
= Examples =
<blockquote>
<blockquote>
You can select items from [[javascript]] using css selectors.
<syntaxhighlight lang="javascript">
<syntaxhighlight lang="javascript">
document.querySelector('div.foo-class');      // find items by CSS-selector
document.querySelector('div.foo-class');      // find items by CSS-selector

Revision as of 16:32, 1 September 2021

Query/Manipulate an HTML page from javascript using it's DOM (domain-object-model).

Documentation

DOM docs https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model

Examples

You can select items from javascript using css selectors.

document.querySelector('div.foo-class');      // find items by CSS-selector
document.getElementById('foo-id');            // find element with ID
document.getElementsByClassName('foo-class'); // find elements with class