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 8541821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:55:04+00:00 2026-06-11T11:55:04+00:00

I have created a jQuery menu which will open when clicking on a small

  • 0

I have created a jQuery menu which will open when clicking on a small icon. This menu contains some links which are clickable and one link which will do some js actions and create a new textbox within the same menu. But when I click on the links, the menu automatically closes. So even if a textbox is displayed, it cannot be seen until we click that icon again to see the menu.

Here is a demo: http://jsfiddle.net/W2exq/1/

I have used some jQuery codes to show and hide the menu and also to display a textbox. So how can I maintain the menu opened, unless we click outside the menu to close it?
Please let me know if you need any other things.


HTML:

<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js></script>
        <link rel="stylesheet" type="text/css" href="http://tharunjose.com/stack/style.css" />
</head>
<div class="notes">
    <div class="noteTooltip">
        This link is for the special purpose of the main site.<hr />
        <a class="noteEdit" id="add_btn" href="#">Edit note</a>
        <a class="noteTrash" href="#"></a>
    </div>
</div>​

CSS:

.notes{
    position:relative;
    width:16px;
    height:16px;
    margin:0 auto;
    background:url(http://tharunjose.com/stack/images/icons.png) no-repeat scroll -228px -34px transparent;
}
.notes:hover{
    cursor:pointer;
    background-position:-207px -34px;
}
.noteTooltip{
    display:none;
    position:absolute;
    top:25px;
    left:-10px;
    width:130px;
    text-align:left;
    line-height:18px;
    border:2px solid #363636;
    z-index:9999;
    background:#fbfbfb;
    -webkit-border-radius:3px;
    -moz-border-radius:3px;
    border-radius:3px;
    padding:10px 10px 6px 10px;
    cursor:auto;
}
.noteTooltip:before{
    content:'';
    position:absolute;
    top:-10px;
    left:10px;
    width:0;
    height:0;
    border-left:5px solid transparent;
    border-right:5px solid transparent;
    border-bottom:8px solid #000;
    z-index:9999;
}
.noteEdit{
    color:#3ba5d5;
    text-decoration:none;
    float:left;
}
.noteTrash{
    display:block;
    float:right;
    padding:6px;
    background:url(http://tharunjose.com/stack/images/icons.png) no-repeat scroll -20px -106px transparent;
}​

JS:

$(document).ready(function() {  
    $(document).click(function(e) {
        $(".createNew, .username, .notes, .pageHelp, .buttons").removeClass("open");
    });
    $(".createNew, .username, .notes, .pageHelp, .buttons").click(function(e) {
        e.stopPropagation(); // this prevents it closing via document.click
        $(this).toggleClass("open");
    });


       var handler_func = function () {
        var i = (typeof this.rel != 'undefined') && (this.rel - 0) == this.rel ? this.rel : 0;
        var e = document.createElement('input');
        e.type='text';
        e.width=40;
        e.name = 'added'+i;
        this.rel = i+1;
        this.parentNode.appendChild(e);
        return false;       
        }

        var add_btn = document.getElementById('add_btn');
        if(add_btn.attachEvent)
              add_btn.attachEvent('onClick', handler_func);
        else if(add_btn.addEventListener) //Firefox & company
              add_btn.addEventListener('click', handler_func, false);
});

​

  • 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-11T11:55:05+00:00Added an answer on June 11, 2026 at 11:55 am

    You need to stop the “click” event from bubbling up the DOM and causing it to close your “popup” menu.

    This is imperfect (allows you to create multiple text elements, I’m not going to do all your work 😛 ) but should give you a good starting point:

    $(document).ready(function() {  
        $(document).click(function(e) {
            $(".createNew, .username, .notes, .pageHelp, .buttons").removeClass("open");
        });
    
        $(".createNew, .username, .notes, .pageHelp, .buttons").click(function(e) {
            e.stopPropagation(); // this prevents it closing via document.click
            $(this).toggleClass("open");
        });
    
        $(".noteTooltip").click(function(e) {
            e.stopPropagation(); //stop the onclick call bubbling up the DOM.
            e.preventDefault(); //stop the onclick call bubbling up the DOM.
        });
    
        $("#add_btn").click(function(event) {
           var i = (typeof this.rel != 'undefined') && (this.rel - 0) == this.rel ? this.rel : 0,
               element = document.createElement('input');
    
           event.stopPropagation();  //stop the onclick call bubbling up the DOM.
           element.type='text';
           element.width=40;
           element.name = 'added'+i;
           this.rel = i+1;
           this.parentNode.appendChild(element);
           return false;   
        });
    
    });
    

    event.stopPropagation() Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

    A blog post on event bubbling also.

    jsFiddle example.

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created some JQuery that will expand a div 'popup' on hover and
I have created a jquery plugin to expand/collapse ul,li something like a accordion menu
I have created a dropdown menu with jquery: here Everything is ok but in
I have created a drop down menu using JQuery but when I test it
I have created a jQuery animation that can be seen by clicking the Preview
I'm having this problem where a floating widget I'm designing, which contains the jQuery
I have created an HTML page which uses simple CSS (no javascript) for menu
I have created a navigation menu which uses javascript. I have drop down menus
Some background: I have a site header and created some jQuery code that displays
I have a menu which is stylized through jquery and CSS so the structure

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.