Posts

Showing posts with the label each

javascript : domElementList .each( function )

  javascript : domElementList .each( fn ) Target: Applicable with any DOM element / elements list. getElementById getElementsByTagName getElementsByClassName getElementsByName querySelector querySelectorAll Description : executes the function in loop with each element in loop and return elements list. Note: loop function this represent individual element in list. Syntax: DOMElement.each(function(){  /*this element related statement*/  }) DOMNodeList.each(function(){  /*this element related statement*/  }) HTMLCollection.each(function(){  /*this element related statement*/  }) Usase: document.getElementById('firstDiv').each(function(){this.style.color='red';}) it executes the function passed and set firstDiv element's style color red. document.getElementsByTagName('div').each(function(){this.style.color='red';}) It loop for each div element and executes function for every div and set it's color style to red. document.getElementsByClassName('Fi...