javascript .prevAll()

 

javascript .prevAll()


Target:

Applicable with any DOM element.

  • getElementById
  • getElementsByTagName
  • getElementsByClassName
  • getElementsByName
  • querySelector
  • querySelectorAll
  • select
  • etc.

Description :

return DOMNodeList of prev all sibling elements of selected element.


Note: if selector is DOM Elements List then first node element's previous all sibling nodes return as DOMNodeList.


Syntax:

DOMElement.prevAll()

DOMNodeList.prevAll()

HTMLCollection.prevAll()


Usase:

  1. document.getElementById('firstDiv').prevAll()
    it search element having id firstDive and return all elements previous to it in same parent as DOMNodeList.
  2. document.getElementsByTagName('div').prevAll()
    the getElementsByTagName selects all div and prevAll() method return first div's previous all sibling nodes as DOMNodeList
  3. document.getElementsByClassName('FirstDiv').prevAll()
    the getElementsByClassName selects all div having class "FirstDiv" and prevAll() method return first element's previous all sibling nodes as DOMNodeList.
  4. document.getElementsByName('FirstDiv').prevAll()
    the getElementsByName selects all elements having name attribute "FirstDiv" and prevAll() method return first element's previous all sibling nodes as DOMNodeList.
  5. document.querySelector('.FirstDiv').prevAll()
    the querySelector selects first div having class "FirstDiv" and prevAll() method return previous all elements as DOMNodeList.
  6. document.querySelectorAll('.FirstDiv').prevAll()
    the querySelectorAll selects all div having class "FirstDiv" and prevAll() method return first element's previous all sibling nodes as DOMNodeList.



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

Popular posts from this blog

javascript : String.right

javascript : String.left

javascript : .nextAll()