[Django]-Clicking a popover scrolls back to top of the page [Bootstrap and Django]

42👍

You can solve that by preventing the default action of the anchor element:

$('a#testpop').on('click', function(e) {e.preventDefault(); return true;});

34👍

You can add href=”javascript://” to the anchor tag.

30👍

Remove the href=”#” tag, it should work.

3👍

This can also be cause by having an element with autofocus=on within the popover (tested in chrome)

1👍

You can replace href="#..." with data-target="#..."

0👍

I’m using Bootstrap 2.3.2

The point is not about clicking. Even if I call show popover programatically, it scrolls me up to the top.

The point is on bootstrap tooltip show function. There is a line there:

$tip.detach().css({ top: 0, left: 0, display: 'block' })

It applies the display block when detaching tip just to get its height and width. This is a metaphysical question! Invisible elements do not have a height!! To fix this I commented that line and added:

$tip.show();

Just after the line where it gets a position:

pos = this.getPosition()

It worked to me.

0👍

I encountered the same problem with Bootstrap v3.3.2 and solved it by using buttons instead of anchor tags.

I then went back to Bootstrap docs and found that all but one of the popover examples given there use buttons – and surprise surprise – the one that does use the anchor leaves out the href attribute!

0👍

just add onclick="return false;" to Anchor element

👤Kumara

Leave a comment