All files / src/previous-sibling-polyfill index.js

100% Statements 6/6
100% Branches 2/2
100% Functions 1/1
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21                1x   1x   2x 1x   1x       1x  
/**
 * Gets the element node that is a sibling to this element node (a direct child of the same parent) and is immediately
 * previous to it in the DOM tree. It's a fix for IE that does not support :nth-child pseudoselector
 * @param {HTMLElement} element - DOM node
 * @return {string} Unique CSS selector for the given DOM node
 */
function previousElementSiblingPolyfill(element)
{
  element = element.previousSibling
  // Loop through ignoring anything not an element
  while(element !== null)
  {
    if(element.nodeType === Node.ELEMENT_NODE)
      return element
    else
      element = element.previousSibling
  }
}
 
module.exports = previousElementSiblingPolyfill