Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap dropdown open on pageload

Ive got this dropdown styled with bootstrap:

<li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#" id="posuvnik">15min <strong class="caret"></strong></a>

    <ul class="dropdown-menu">
        <li> <a href="#" onclick="setPosuvnik(1)">15min</a> </li>
        <li> <a href="#" onclick="setPosuvnik(2)">1hod</a> </li>
    </ul>
</li>

and I want that dropdown menu to be rolled down on a page load, anyone know how to achieve that? thanks in advance :)

like image 849
Julius ShadowAspect Flimmel Avatar asked May 01 '26 10:05

Julius ShadowAspect Flimmel


2 Answers

The dropdown is toggled with having the additional class 'open' added to the enclosing <li> element. So if you want to have it open on page loading:

<li class="dropdown open">

That will do the trick.

like image 101
Neocult Avatar answered May 02 '26 22:05

Neocult


This little bit of jQuery script (I'm assuming you've loaded it becasue you're using Bootstrap) ought to do the trick. Once the DOM has loaded, it sends a click() to the dropdown toggle button.

$(document).ready(function () {
    $("#posuvnik").click();
});

There is probably a way to do it in straight CSS, but without seeing more of your code it's hard to know.

like image 23
Olly Hodgson Avatar answered May 02 '26 23:05

Olly Hodgson