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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:16:03+00:00 2026-06-09T12:16:03+00:00

I need to generate this 4 JQuery calls inside a Javascript Function: $(.dropdown-menu .1_147).hover(

  • 0

I need to generate this 4 JQuery calls inside a Javascript Function:

$(".dropdown-menu .1_147").hover(
  function() { $("#1_147").show(); },
  function() { $("#1_147").hide(); }
);

$(".dropdown-menu .2_147").hover(
  function() { $("#2_147").show(); },
  function() { $("#2_147").hide(); }
);

$(".dropdown-menu .3_147").hover(
  function() { $("#3_147").show(); },
  function() { $("#3_147").hide(); }
);

$(".dropdown-menu .4_147").hover(
  function() { $("#4_147").show(); },
  function() { $("#4_147").hide(); }
);

I’ve write a Javascript function, the FOR loop only generates the last interaction “4_147”. How can I tell the Javascript to generate the 4 JQuery calls?

My current JavaScript:

var submenu_navigation = document.getElementsByClassName("dropdown-menu");
var submenu_navigation_list = submenu_navigation[0].getElementsByTagName('li');

/*console.log(submenu_navigation_list);*/

function generateDropdownMenuMoldura(lis_array) {

    for (var item in lis_array) {

        var item_class_attr_name = lis_array[item].getAttribute('class');

        console.log(item_class_attr_name);

        $(".dropdown-menu ." + item_class_attr_name).hover(
          function() { $("#" + item_class_attr_name).show(); },
          function() { $("#" + item_class_attr_name).hide(); }
        );


    }   
}


generateDropdownMenuMoldura(submenu_navigation_list);

Any clues?

Best Regards,


Update:

I got the solution:

/* Define the Elements that I need to loop */
var submenu_navigation = document.getElementsByClassName("dropdown-menu");
var submenu_navigation_list = submenu_navigation[0].getElementsByTagName('li');


function generateDropdownMenuMoldura(lis_array) {

    for (var item in lis_array) {

        var item_class_attr_name = lis_array[item].getAttribute('class');

        console.log(item_class_attr_name);

        (function(item_class_attr_name) {
            $(".dropdown-menu ." + item_class_attr_name).hover(
              function() { $("#" + item_class_attr_name).show(); },
              function() { $("#" + item_class_attr_name).hide(); }
            );
        })(item_class_attr_name);


    }   
}


generateDropdownMenuMoldura(submenu_navigation_list);

My question is: How this anonymous function call works? This is a recursion technique?

Best Regards,

  • 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-09T12:16:05+00:00Added an answer on June 9, 2026 at 12:16 pm

    How to fix your specific solution was already answered in an other question.

    But why so complicated? Judging from the JavaScript you currently have, and assuming everything apart from the scope works fine, a simpler solution would be:

    $(".dropdown-menu li").hover(function() { 
        $('#' + this.className).show(); 
    }, function() { 
        $('#' + this.className).hide();
    });
    

    There is no need to bind a different handler to each of these elements, since they all do basically the same thing.

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

Sidebar

Related Questions

Hey. I need some help with jQuery Ajax calls. In javascript I have to
I need to generate Entities/Object from selected tables - not all. Is this possible
I need to generate a file for Excel, some of the values in this
I need to generate a string of incrementing dates, something like this: (year, month,
i need to look xsd file for generate code so i need this document
I have this in my controller. I need my view to generate some HTML,
I need to generate a couple of objects from lists in Javascript. In Python,
I am learning JQuery. I have a need to create a custom control. This
A few days ago I posted this question: switch statement and loops using jquery/javascript
I have followed this tutorial which uses jQuery UI to generate Facebook tokens like:

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.