javascript - How to go on a specific element on a page -
yes, there link "how go on specific element on page" followed, before mark duplicate, read this.
i tested every bit of code given on link , none of them worked.
i have search field gives user option search. if search button clicked element should scrolled to. logged in console element, retrieved , shown in console, of given functions in link not work. way, bootstrap panel filled accordions, maybe why problem exists, should send me accordion atleast.
//search button click $("#searchbutton").click(function() { var searchinfo = document.getelementbyid("search"); console.log(searchinfo.value); var playernamer = findplayerby(playerlst,searchinfo.value,null); if (playernamer == false){ //do nothing, if search fails } else{ console.log(document.getelementbyid("id_"+playernamer.pos)); window.scroll(0,findpos(document.getelementbyid("id_"+playernamer.pos))); } }); function findpos(obj) { var curtop = 0; if (obj.offsetparent) { { curtop += obj.offsettop; } while (obj = obj.offsetparent); return [curtop]; } }
now can see on searchbutton click have few console.log-s. these things return right result, 1 of example functions page left in code not working.
i present console output image cause copying in opera console didn't work quite expected:
the example may bit misleading though, because used top element. have element in bottom can't seen on screen , there isn't scroll happening either (element id of 8).
change scroll
scrolltop
:
$(window).scrolltop(findpos(document.getelementbyid("id_"+playernamer.pos)));
Comments
Post a Comment