Advertisement
146f73

Untitled

Oct 25th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///scroll to element by xpath
  2. ///tested at: https://www.w3schools.com
  3.  
  4. function getElementByXpath(path) {
  5.   return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  6. }
  7. function findPos(obj) {
  8.     var curtop = 0;
  9.     if (obj.offsetParent) {
  10.         do {
  11.             curtop += obj.offsetTop;
  12.         } while (obj = obj.offsetParent);
  13.     return [curtop];
  14.     }
  15. }
  16.  
  17. //calling:
  18. window.scroll(0,findPos(getElementByXpath("//a[contains(text(),'LEARN JQUERY')]")));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement