Part 34 | JavaScript Tutorial | DOM methods | getElementById | ElementsByTagName | querySelectorAll

Published: 04 March 2023
on channel: Trinits Technologies
65
0

DOM stands for Document Object Model.
The HTML DOM is a standard for how to get, change, add, or delete HTML elements.

Find the HTML elements:-
-------------------------
document.getElementById(id)
Find an element by element id
document.getElementsByTagName(name)
Find elements by tag name
document.getElementsByClassName(name)
Find elements by class name

document.querySelectorAll("p.intro");
Find elements based on css selectors.

Change the HTML element values:
---------------------------
element.innerHTML = new html content
Change the inner HTML of an element

element.attribute = new value
Change the attribute value of an HTML element


element.style.property = new style
Change the style of an HTML element

Adding and Deleting Elements:-
------------------------------
document.createElement(element)
Create an HTML element

const div = document.createElement('div'); // create new div element
div.textContent = 'Hello, world!'; // set the text content of the div
document.body.appendChild(div); // append the div to the document body


document.removeChild(element)
Remove an HTML element

const img = document.getElementById('myImage'); // get the image element
document.body.removeChild(img); // remove the image from the document body

document.appendChild(element)
Add an HTML element
const div = document.createElement('div'); // create new div element
div.textContent = 'Hello, world!'; // set the text content of the div
document.body.appendChild(div); // append the div to the document body

Add events using Javascript code.:-
document.getElementById(id).onclick = function(){code}


On this page of the site you can watch the video online Part 34 | JavaScript Tutorial | DOM methods | getElementById | ElementsByTagName | querySelectorAll with a duration of hours minute second in good quality, which was uploaded by the user Trinits Technologies 04 March 2023, share the link with friends and acquaintances, this video has already been watched 65 times on youtube and it was liked by 0 viewers. Enjoy your viewing!