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

  • Home
  • SEARCH
  • 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 8439901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:08:06+00:00 2026-06-10T08:08:06+00:00

I have some issues with understanding jQuery on. If i have a UL which

  • 0

I have some issues with understanding jQuery on.

If i have a UL which has some dynamic Li elements created via jquery, which will set the first li to have the class selected – e.g.

<li class='selected'>text</li>  

EDIT UDPATE:

Ok..so what i have is a set of dynamically generated LI from a REST call which is dynamically generated from a text box. What i need to happen is to essentially after i type in (keyup) i will get some results displayed (similar to autocomplete). What i then need to do is from within the context of the search box detect the up and down arrows and move the “.selected” class up and down the tree. The code below works for static lists, just not dynamically created ones.

some example code:

$('.txtSearchBox')
.unbind('keypress keyup')
.bind('keypress keyup', function (e) {
    if ($(this).val().length < 3 && e.keyCode != 13) {
        $('.searchWrapper').hide();
    } else {
        $('.searchWrapper').show();
        SearchAutoComplete.init($('.searchWrapper'));
        SearchAutoComplete.load();
    }

    if (e.keyCode == 38) { // up
        var selected = $(".selected");
        $(".searchWrapper li").removeClass("selected");
        if (selected.prev().length == 0) {
            selected.parent().children().last().addClass("selected");
        } else {
            selected.prev().addClass("selected");
        }
    }
    if (e.keyCode == 40) { // down
        var selected = $(".selected");
        $(".searchWrapper li").removeClass("selected");
        if (selected.next().length == 0) {
            selected.parent().children().first().addClass("selected");
        } else {
            selected.next().addClass("selected");
        }
    }
});

$(".searchWrapper li").live('mouseover', function (e) {
    $(".searchWrapper li").removeClass("selected");
    $(this).addClass("selected");
});

As you can see this code detects the up and down arrow keys. The problem is for dynamic elements this does nothing. Im just confused as the on event should be on the li not the a?

Thanks

Chris

  • 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-10T08:08:07+00:00Added an answer on June 10, 2026 at 8:08 am

    Try this:

    $(".searchWrapper ul").on('mouseover',"li", function () {
        $(".searchWrapper li").removeClass("selected");
        $(this).addClass("selected");
    });
    

    From the JQuery docs when you provide a selector to the on() function (“li”) the event handler is delegated.

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

Sidebar

Related Questions

I have some issues in setting the classpath for the a project for which
I'm have some issues adding a class to 2 navigation links on a theme.
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
I have created simple .aspx page which queries a database for some live data
I'm missing some fundamental understanding of javascript function flow control... I've created a jquery
I have some issues with a PHP file that is not working properly. The
I have some issues with my EJB 3 timer where it is launched more
I seems to have some issues in order to compile gproc from uwiger. I
Im starting with CoCos2d development and I think I have some issues with nodespace,
I am integrating PayPal in my website But I have some issues in it.

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.