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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:12:48+00:00 2026-06-18T03:12:48+00:00

http://jsfiddle.net/Ht8eP/3/ In the previous example I catch every clicked list item explicitly by it’s

  • 0

http://jsfiddle.net/Ht8eP/3/

In the previous example I catch every clicked list item explicitly by it’s ID, which isn’t practical & efficient specially with too many items. What I want to achieve is to get it dynamically without hard coding all list items.

$(function() {
    $("#a1").click(function()
    {
        document.getElementById("dropdown").innerHTML = "A-1";
        document.getElementById("result").innerHTML = process("a1");
    });

    $("#a2").click(function()
    {
        document.getElementById("dropdown").innerHTML = "A-2";
        document.getElementById("result").innerHTML = process("a2");
    });

    $("#a3").click(function()
    {
        document.getElementById("dropdown").innerHTML = "A-3";
        document.getElementById("result").innerHTML = process("a3");
    });
});

function process(param)
{
    // Some processing!
    return param;
}
  • 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-18T03:12:49+00:00Added an answer on June 18, 2026 at 3:12 am

    To use your existing code, changing it as little as possible you can bind to the ul.dropdown-menu li instead and get the HTML from the a inside it and use the current (this) li‘s id value, similar to this:

    $("ul.dropdown-menu li").click(function() {
        var $link = $(this);
        document.getElementById("dropdown").innerHTML = $("a", $link).html();
        document.getElementById("result").innerHTML = process(this.id);
    });
    

    DEMO – Replacing multiple with single click event


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

Sidebar

Related Questions

http://jsfiddle.net/waitinforatrain/8AqgU/ The example in that link shows a nested ordered list. If you open
http://jsfiddle.net/D6be5/ HTML <table class=example border=1> <tr> <td> <label>Enter text</label> <textarea>Enter text</textarea> </td> </tr> <tr
http://jsfiddle.net/nicktheandroid/6BAfH/1/ The list-elements are sorted accordingly by the number in their span. Why is
http://jsfiddle.net/CbL7W/ example of scroll event behavior. I have this script that is working correctly
http://jsfiddle.net/yxhzU/1042/ I'm trying to modify this example so that within the top carousel you
http://jsfiddle.net/MzqYL/3/ In the example above the border of the frame is thinner than the
http://jsfiddle.net/AndyMP/UpLts/1/ This is just an example for illustrative purposes, but what I want to
http://jsfiddle.net/nicktheandroid/GPFxM/28/ I've also explained the situation in the JS Fiddle example. I binded hover
http://jsfiddle.net/nFFuD/ I'm trying to animate the search field in this example using jquery, making
http://jsfiddle.net/AYPze/9/ In this example I have two similar divs with the same goal. Bind

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.