Posts

Showing posts with the label toggleClass

javascript domElement .toggleClass(className)

  javascript domElement .toggleClass( className ) Target: Applicable with any DOM element. getElementById getElementsByTagName getElementsByClassName getElementsByName querySelector querySelectorAll Description : Toggle givent className with element(s) classList. That's mean if not exists then add and if exist then remove. Note: after toggling class of element/elements list it return itself for further processing. Syntax: DOMElement.toggleClass(' className ') DOMNodeList.toggleClass(' className ') HTMLCollection.toggleClass(' className ') Usase: document.getElementById('firstDiv').toggleClass(' myClass ') it toggle 'myClass' with the div having id firstDiv and return firstDiv element document.getElementsByTagName('div').toggleClass(' myClass ') the getElementsByTagName selects all div and toggleClass() method toggle class name 'myClass' with all divs and return getElementsByTagName result for further processing...