11

Hi I have just started using twitter bootstrap and trying my hand on handling dropdown events.

I want to handle the dropdown item selected event, that is, when the user clicks on a particular item, a table should be displayed just below the dropdown. Can anyone please help me out in achieving this? Thank you.

<ul class="dropdown-menu">
    <!-- dropdown menu links -->
    <li><a href="#" id="action-1">How are you?</a></li>
    <li><a href="#2">What is your name</a></li>
    <li><a href="#section-2">Section 2</a></li>
</ul>
2
  • I am sorry,actually I intend to type the html code for dropdown,but its not getting displayed. I am sorry again,I am new to this forum,but please help me out. Commented Sep 16, 2013 at 6:06
  • 1
    I have formatted the code, but just so you know for that you just select the code and press the {} button in the formatting area Commented Sep 16, 2013 at 6:07

2 Answers 2

18

There's no such event in Bootstrap, the only events you can handle for dropdowns are show, shown, hide, hidden, you can use simple jQuery for this though:

$('.dropdown-menu a').click(function(){
    //Show table
});
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for the edit and the response,in the jQuery,should I write the entire code for table? I typed the code but it gives me errors,what should I do?
@user2782692 I'm not sure what you're trying to do but you should learn the basics of DOM manipulation with jQuery, I suggest you read this, there's a section on creating new DOM elements
thanks,I am trying to create a html table in jQuery so that when the user clicks on the particular item on the dropdown list,the table will be displayed,can you please give me an idea of how this can be done?
@user2782692 the approach will depend on your needs, do you really need to build the table on each click? can't you build the table on page load and just hide/show it when a link is clicked? but before anything you should really get a grasp on jquery, that's why I suggest you read the link I gave you
0

You can handle the function in the menu itself, e.g.

<li><a href="javascript:itemSelected('A')">A. Hello World!</a></li>

3 Comments

inline JS is slightly evil
Yeah... don't do that. This is difficult to maintain, nor is it elegant. There are much better ways.
This is neither inelegant, nor difficult to maintain when the page is generated by Flask/Jinga.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.