MShack MShack - 5 months ago 11
Javascript Question

how to prevent jump to top of page

not sure why i'm having this problem. This is only happening on mobile IOS devices. Every time i click , it jumps to top of page

var thisImageClick = '<i class="fa fa-times-circle" data-placement="left" title="Remove Player" style="cursor:pointer" onclick="removeStarter(\''+positionID+'\'); return false;"></i>';


I tried adding
return false;

but that wouldn't work , any ideas ?

Here is removeStarter function

function removeStarter(positionID){
previousLineupTab = currentLineupTab;
switch(positionID) {
case "QB": currentLineupTab=0; break;
case "RB1":
case "RB2": currentLineupTab=1; break;
case "WR1":
case "WR2":
case "WR3": currentLineupTab=2; break;
case "TE": currentLineupTab=3; break;
case "FLEX": currentLineupTab=4; flexPlayer=""; break;
case "D": currentLineupTab=5; break;
}
var pid = starterArray[positionID];
starterArray[positionID]='';
sourceList["pid_"+pid].Selected = false;
populateStarters(false);
showLineupTab(currentLineupTab,false,false);
}

Answer

Consider not use onclick directly on your element, you may use jquery function to execute this action as a event listener.

But considering that you will not change your actual solution, you may to the following:

<i class="fa fa-times-circle" data-placement="left" title="Remove Player" style="cursor:pointer" onclick="removeStarter(\''+positionID+'\'); return false;"></i>

Ref: http://biostall.com/page-jumping-to-top-when-clicking-link-containing-click-event/

Comments