If you want to create a new element in the DOM, you can do as follows:
Var myDiv = document.createElement(‘div’);
If you want to add a new element to the existing element, you can do as follows.
Here I am appending a div to the body.
If you want to add some styles to an existing element, you can do as follows.
div.style.right = ‘142px’; div.style.left = ’26px’; Modification
If you want to assign a class name to an existing element, you can do as follows:
div.className = ‘myClassName’;
div.id = ‘myID’;
Change the contents
div.innerHTML = ‘<div class=”myClassName”>This is my HTML</div>’;
div.textContent = ‘This is my text’;
To remove an element from the DOM:
Here we are removing a div from the parent node.
We can access the elements in several ways. Let us see that now.
document.querySelector(‘div #myID .myClassName’);
That’s all for today. I hope someone finds this useful. Thanks for reading.