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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:42:01+00:00 2026-06-04T05:42:01+00:00

I get 2 alert when I click on the sub menu, the pop up

  • 0

I get 2 alert when I click on the sub menu, the pop up first says 1 and then a second pop up gives me 2. I would like the alert to be 0,1,2,3 etc in correct sequence as per navigating an array. Is it not the sub menu item just the following item in an array?

<ul id="menu">
   <li><a href="page1">Item 1</a></li>
   <li><a href="page2">Item 2</a> 
      <ul id="sub-menu">
           <li><a href="page3">Item 3</a></li>
      </ul>
   </li>
   <li><a href="page4">Item 4</a></li>
</ul>

Jquery:

jQuery (function($) {
  $("#menu .menu li").each(function (index) {
     var item = $(this);
     $("a", item).click(function (e) {
        e.preventDefault();
        alert(index);
     });
  });
});
  • 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-04T05:42:03+00:00Added an answer on June 4, 2026 at 5:42 am

    A way without using event.stopPropagation():

    jQuery (function($) {
      $("#menu .menu li").each(function (index) {
        var item = $(this);
        $("> a", item).click(function (e) {
          e.preventDefault();
          alert(index);
        });
      });
    });​
    

    It will only trigger for the immediate child of li.

    Here is the working example.

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

Sidebar

Related Questions

Here is some javascript/jquery code: $('#button').click(function() { $.get(php/doit.php?id=<? echo $r['id']; ?>, function(html) { alert(html);
how to pass the strMessage (from codebehind to the script) to get the alert
I'm new to jquery. I'm trying to get an alert box to popup with
This is my problem. Every time I load the page, I get an alert
I am trying to get the following form submission to show alert box if
I want to get HTML source of select text in div and alert that.
$.get($(this).attr('id'), function(data){ var qp_post = $(data).filter('title'); alert(qp_post); }); This fetches the content fine however
No functions get called, and I can't even alert. It is just an external
We can easily alert anything in java script. Is it possible to get this
$.get($(this).attr('rel'), function(response){}, 'script') .error(function(){ alert('this failed')}); I get. .error is not a method .

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.