JavaScript Learning HTML Element Selector

 


familiar with DOM (Document Object Model).

Gets Syntax Method
ID #name getElementById()
class .name getElementsByClassName()
Tag h1,p etc. getElementsByTagName()
Selector (Single) .classname, #idName querySelector('.className'), querySelector('#idName')
Selector (all) .className querySelctorAll()



Elements by ID: single element in the DOM is by its unique ID. We can get or modify an element by ID with the getElementById() method of the document object.
document.getElementById(elementID);

className: The className property sets or returns the class name of an element childNodes: The childNodes property returns a collection of a node's child nodes. 

parentNode: The parentNode property returns the parent node of the specified node. innerText: The innerText property sets or returns the text content of the specified node. innerHTML: The innerHTML property sets or returns the HTML content of an element.

<h1 id="demo">Heading 1</h1>
    console.log('demoId');

Comments