Frequently Asked Questions?
The DOM(Document Object Model) is a kind of structure of a webpage. It allows JavaScript to to many work. Such as, changing the content, change or create HTML elements, buttons desing and also allow to add styles and many more.
Well, there is some way to select an element from the DOM.
- 1. document.getElementById()
- 2. document.getElementsByClassName()
- 3. document.getElementsByTagName()
- 4. document.querySelector()
- 5. document.querySelectorAll(), etc.
Event delegation is a JavaScript technique where we can add an event listener to a parent element instead of adding event listener to individual elements. When any event is occurs on a child element's it bubble up to his parent.
We can manipulate an element's attribute or style by following these methods:
- 1. element.setAttribute('attribute', 'value')
- 1. element.removeAttribute('value')
- 2. element.style.property = 'value'
We can add style to element's using element.style.property = 'value' method.
We can remove attribute from element's using element.removeAttribute('value') method. etc.