javascript : domElement .addClass(className)
javascript : domElement .addClass(className)
Target:
Applicable with any DOM element.
- getElementById
- getElementsByTagName
- getElementsByClassName
- getElementsByName
- querySelector
- querySelectorAll
Description :
add givent className to element(s) classList.
Note: after adding class of element/elements list it return itself for further processing.
Syntax:
DOMElement.addClass('className')
DOMNodeList.addClass('className')
HTMLCollection.addClass('className')
Usase:
- document.getElementById('firstDiv').addClass('myClass')
it add 'myClass' to the div having id firstDiv and return firstDiv element - document.getElementsByTagName('div').addClass('myClass')
the getElementsByTagName selects all div and addClass() method add class name 'myClass' to all divs and return getElementsByTagName result for further processing you do not need to execute selector again. - document.getElementsByClassName('FirstDiv').addClass('myClass')
the getElementsByClassName selects all div having class "FirstDiv" and addClass() method add class name 'myClass' to all divs and return getElementsByClassName result for further processing you do not need to execute selector again. - document.getElementsByName('FirstDiv').addClass('myClass')
the getElementsByName selects all elements having name attribute "FirstDiv" and addClass() method add class name 'myClass' to all elements and return getElementsByName result for further processing you do not need to execute selector again. - document.querySelector('.FirstDiv').addClass('myClass')
the querySelector selects first div having class "FirstDiv" and addClass() method add class name 'myClass' to it and return querySelector result for further processing you do not need to execute selector again. - document.querySelectorAll('.FirstDiv').addClass('myClass')
the querySelectorAll selects all div having class "FirstDiv" and addClass() method add class name 'myClass' to all divs and return querySelectorAll result for further processing you do not need to execute selector again.
Download MYJS.js
MyJs is a collection of java script extension methods that enhances the JavaScript objects, class object, DOM element, domElementsCollections, Date, String, Number and other data type.
Include in you project landing page (master page) and it will extends your DOM and JavaScript Objects.
Comments
Post a Comment