javascript : domElement .hasClass( className )
javascript : domElement .hasClass(className)
Target:
Applicable with any DOM element.
- getElementById
- getElementsByTagName
- getElementsByClassName
- getElementsByName
- querySelector
- querySelectorAll
Description :
return true/false if givent className exist with element classList. In case of elementsList it check first element's classList and return true/false.
Syntax:
DOMElement.hasClass('className')
DOMNodeList.hasClass('className')
HTMLCollection.hasClass('className')
Usase:
- document.getElementById('firstDiv').hasClass('myClass')
it check the div having id firstDiv classList contains className 'myClass' if contains then return true other wise false - document.getElementsByTagName('div').hasClass('myClass')
the getElementsByTagName selects all div and hasClass() method check class name 'myClass' in first div's classList for existance and return true/false - document.getElementsByClassName('FirstDiv').hasClass('myClass')
the getElementsByClassName selects all div having class "FirstDiv" and hasClass() method check class name 'myClass' in first div's classList and return true/false. - document.getElementsByName('FirstDiv').hasClass('myClass')
the getElementsByName selects all elements having name attribute "FirstDiv" and hasClass() method check class name 'myClass' in first div classList and return true/false. - document.querySelector('.FirstDiv').hasClass('myClass')
the querySelector selects first div having class "FirstDiv" and hasClass() method check class name 'myClass' in it's classList and return true/false. - document.querySelectorAll('.FirstDiv').hasClass('myClass')
the querySelectorAll selects all div having class "FirstDiv" and hasClass() method check class name 'myClass' in first div's classList and return true/false.
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