Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Drop Down Menu Causes Focus to Shift to Top of Page

I have a Bootstrap drop down menu. When I select a value from the drop down menu, the focus shifts to the top of the page. The class options for the drop down menu are as follows:

<a class = "btn dropdown-toggle" data-toggle = "dropdown" data-target = "#">
    <span class = "caret"></span>
</a>

jFiddle example here. You'll need to scroll down on the results window to the see drop down menu.

What's the best way to remedy this behavior?

like image 715
Lloyd Banks Avatar asked Mar 28 '13 19:03

Lloyd Banks


1 Answers

In your code you have # anchors.

When someone clicks on this, the browser will go to the top of the page in search for an anchor that does not exist.

Even if you remove the #, the link will think it needs to refresh the page.

If you need the anchor for styling, do something like this:

<a href = "javascript:return false;">link text</a>

http://jsfiddle.net/W7gbj/7/

like image 181
Jimmyt1988 Avatar answered Jan 04 '23 11:01

Jimmyt1988