0% found this document useful (0 votes)
18 views2 pages

Notice 1

Uploaded by

rahulgupta79777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Notice 1

Uploaded by

rahulgupta79777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Essential DOM Manipulation Methods

Selecting Elements
`document.getElementById('id')` - Selects an element by its ID.
`document.getElementsByClassName('class')` - Selects elements by their class name.
`document.getElementsByTagName('tag')` - Selects elements by their tag name.
`document.querySelector('selector')` - Selects the first element that matches a CSS selector.
`document.querySelectorAll('selector')` - Selects all elements that match a CSS selector.

Manipulating Element Content


`element.innerHTML` - Sets or gets HTML content of an element.
`element.textContent` - Sets or gets text content of an element.
`element.innerText` - Similar to textContent, but reflects styling and visibility.

Modifying Attributes
`element.getAttribute('attribute')` - Gets an attribute's value.
`element.setAttribute('attribute', 'value')` - Sets an attribute's value.
`element.removeAttribute('attribute')` - Removes an attribute.

Styling Elements
`element.style.property = 'value'` - Sets inline style for a property.
`element.classList.add('class')` - Adds a class to the element.
`element.classList.remove('class')` - Removes a class from the element.
`element.classList.toggle('class')` - Toggles a class on the element.

Adding and Removing Elements


`document.createElement('tag')` - Creates a new HTML element.
`element.appendChild(newElement)` - Adds a new child to an element.
`element.removeChild(childElement)` - Removes a child from an element.
`element.insertBefore(newElement, referenceElement)` - Inserts new element before a reference
element.

Event Handling
`element.addEventListener('event', function)` - Attaches an event handler.
`element.removeEventListener('event', function)` - Removes an event handler.

You might also like