Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8100839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:50:51+00:00 2026-06-05T22:50:51+00:00

Short story: stopPropagation() prevents a dropdown menu from closing – which is good. But

  • 0

Short story: stopPropagation() prevents a dropdown menu from closing – which is good. But it also prevents the dropbox from opening next time around – which is bad.

Long story:
I’m using Twitter-Bootstrap and I’ve put a search box inside the dropdown menu like so:

<div id="search_word_menu" style="position:absolute;right:157px;top:60px;"> 
        <ul class="nav nav-pills">
            <li class="dropdown" id="menu200">
                <a class="dropdown-toggle btn-inverse" data-toggle="dropdown" style="width:117px;position:relative;left:2px" href="#menu200">
                <i class="icon-th-list icon-white"></i>
                    Testing
                    <b class="caret"></b>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="#">Retweets</a></li>
                    <li><a href="#">Favourites</a></li>
                    <li class="divider"></li>
                    <li><a href="#">A list</a></li>
                    <li class="divider"></li>
                    <li><a href="#">A saved search</a></li>
                    <li><a href="#">A saved #hashtag</a></li>
                    <li class="divider"></li>
                    <li>
<!--   HERE -->     <input id="drop_search" type="text" class="search_box_in_menu" value="Search...">

                    </li>
                </ul>
            </li>
        </ul>

When I click inside the searchbox, the default behaviour is obviously to close the dropdown – but that makes it rather hard to write in a search term. So I’ve tried with the e.stopPropagation(), which does indeed prevent the dropdown from closing. Then, when I press enter in the searchbox, I’m closing the dropdown with a .toggle() – also seems to work fine.

The PROBLEM arises when I want to to it all again, because the e.stopPropagation() has now disabled the dropdown alltogether – ie. when I press the dropdown menu, it doesn’t open anymore! This is because of stopPropagation(), no doubt – but how can I resolve this, so that I get the aforementioned functionality, but without breaking the rest altogether?

jQuery below:

$(document).ready(function() {
    console.log("document.ready - ");

                //clearing search box on click
    $(".search_box_in_menu").click(function(e) {
        e.stopPropagation(); // works for the specific task
        console.log(".search_box_in_menu - click.");
        if($(this).val() == 'Search...') {
            $(this).val('');
            console.log(".search_box_in_menu - value removed.");

        };
        //return false; //this is e.preventDefault() and e.stopPropagation()


    });

                    // when pressing enter key in search box
    $('.search_box_in_menu').keypress(function(e) {
        var keycode = (e.keyCode ? e.keyCode : e.which);
        if(keycode == '13') {
            console.log(".search_box_in_menu - enter-key pressed.");
            console.log($(this).val());
            $(this).closest('.dropdown-menu').toggle(); //works

        }
    });


    $('.dropdown').click(function() {
        console.log(".dropdown - click.");
        $(this).closest('.dropdown-toggle').toggle(); //does nothing
    });

Would greatly appreciate some help! I’m starting to suspect this might be a bootstrapped-only problem, or at least caused by their implementation – but it’s beyond me atm.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T22:50:53+00:00Added an answer on June 5, 2026 at 10:50 pm

    Found a solution: Using stopPropagation(), and closing box with manual trigger. Then, for some reason (is the stopPropagation() reset?), it works.

    //dealing with the dropdown box
    $(document).ready(function() {
        console.log("document.ready - ");
    
        //clearing search box on click and prevent the dropdown from closing
        $(".search_box_in_menu").click(function(e) {
            e.stopPropagation();
            console.log(".search_box_in_menu - click.");
            if($(this).val() == 'Search...') {
                $(this).val('');
                console.log(".search_box_in_menu - value removed.");
            };
            //return false;         
    
        });
    
        // when pressing enter key in search box
        $('.search_box_in_menu').keypress(function(e) {
            var keycode = (e.keyCode ? e.keyCode : e.which);
            if(keycode == '13') {
                console.log(".search_box_in_menu - enter-key pressed.");
                console.log($(this).val());
                $(this).closest('.dropdown').trigger('click');
            }
        });
    
        //resetting a dirty search box
        $('.dropdown').click(function() {
            if ($(this).closest('.search_box_in_menu').val() == 'Search...') {
                console.log(".search_box_in_menu - clean searchbox.");
            }
            console.log(".dropdown - click.");
        });     
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short Story: I have a layout layout.xml, which gets replaced by another layout success.xml
Long story short: pythonw.exe does nothing, python.exe accepts nothing (which one should I use?)
The short story: What are those reset conditions, which will not set a bit
I'm trying to extract a word list from a Russian short story. #!/bin/sh export
I have a couple different bits of code but the short story is I
Long story short: on Chrome and Safari only, values from a login form are
Long story short: I had to create a chat functionality which seems to work
Long story short: We've got a system that we're moving from one server to
Short story: I can't make precompiled headers work properly with gcc -c option. Long
Short story: struct A{}; struct B:private A{}; void f(void *){} void f(A*){} int main(){

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.