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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:32:32+00:00 2026-06-03T18:32:32+00:00

On my page I numerous sections that I want to highlight when the mouse

  • 0

On my page I numerous sections that I want to highlight when the mouse goes over. This can be accomplished using onmouseover and onmouseout. I have more than 100 sections though and I don’t think that it is very efficient to call the methods on each section. Like so.

<li id="1" onmouseover="h(1)" onmouseout="h(1)">
    <label>1</label>
</li>
<li id="2" onmouseover="h(2)" onmouseout="h(2)">
    <label>2</label>
</li>
<li id="3" onmouseover="h(3)" onmouseout="h(3)">
    do something
</li>
...
<li id="4" onmouseover="h(4)" onmouseout="h(4)">
    do something
</li>

I’m hoping to get this answer in Javascript as I do not know jQuery.

  • 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-03T18:32:34+00:00Added an answer on June 3, 2026 at 6:32 pm

    What you are after is event delegation. That is binding the event handler to a common ancestor. In your case it could be something along the lines:

    // assuming `ul` refers to the list element that contains those `li` elements
    ul.onmouseover = function(event) {
        // some cross-browser handling (IE)
        event = event || window.event;
        var target = event.target || event.srcElement;
    
        // if the event was triggered on a `li` element
        if(target.nodeName === 'LI') {
            h(this.id);  // do the stuff
        }
    };
    

    DEMO

    This is only an example and you have to adjust it to your needs, e.g. if the li elements contain elements themselves, things are a bit different.

    I recommend to read the great articles on quirksmode.org if you want to learn more about event handling.


    That said, jQuery would make this a lot easier, also because it simulates the mouseenter and mouseleave events from IE, which are much more useful, and takes care of the cross-browser issues.

    For example:

    $('#listId').on('mouseenter', 'li', function() {
        h(this.id);
    });
    
    $('#listId').on('mouseleave', 'li', function() {
        h(this.id);
    });
    

    If you work a lot with event handling and/or DOM manipulation, jQuery is really to be recommended.

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

Sidebar

Related Questions

I am taking over a one-page site that uses numerous jQuery show/hide instructions to
I'm receiving this error on a page that previously worked fine, in fact the
I have numerous buttons that go to different views on my main page and
There is an ASP page on work intranet that returns data from numerous sensors.
Using Woodwing, we have a page that has custom html in it, using the
I'm sure this has been asked before, but after numerous searches I can't seem
Now that I can make useful user controls in WPF (thanks to this stackoverflow
I have seen numerous advice on stackexchange and all over the web suggesting that
Page has menu items that would replace a 'div id=foo_(current menu item)' with 'div
page contents: aa<b>1;2'3</b>hh<b>aaa</b>.. .<b>bbb</b> blabla.. i want to get result: 1;2'3aaabbb match tag is

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.