YES, there is a link "How to go on a specific element on a page" which i already followed, so before you mark it as a duplicate, read this.
I tested every bit of the code given on the link and none of them worked.
I have this search field which gives an user an option to search. If search button is clicked the element should be scrolled to. I logged in the console the element, it is retrieved and shown in console, however any of the given functions in the link does not work. By the way, my bootstrap panel is filled with accordions, so maybe this is why the problem exists, however it should send me to the 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) {
do {
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curtop];
}
}
Now as you can see on searchbutton click i have few console.log-s. These things return the right result, however one of the example functions from the page left in the code is not working.
I present my console output as an image cause copying in Opera console didn't work quite as expected:
The example may be a bit misleading though, because i used the top element. I have an element in the bottom which can't be seen on the screen and there isn't the scroll happening either (element with id of 8).