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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:24:31+00:00 2026-05-21T19:24:31+00:00

Ok, I have an unordered list like so: <ul id=list> <li> Item 1 </li>

  • 0

Ok, I have an unordered list like so:

<ul id=list>
    <li> Item 1 </li>
    <li> Item 2 </li>
    <li> Item 3 </li>
    <li> Item 4 </li>
    <li> Item 5 </li>
</ul>

Is there any simple way of creating onclick events for each of the individual li’s?

Here’s my objective… I have CSS setup like so:

#list li {...some styles here...}
#list li:active {...change background color and font color on click...}

So again, any simple way of doing this? I know I can achieve it by simply adding an onclick event to each of the individual li’s, but any smart way of doing this?

(For clarification – I’m actually going to be using an ‘ontouchstart’ event for mobile webkit)

  • 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-05-21T19:24:32+00:00Added an answer on May 21, 2026 at 7:24 pm

    If you do not want to use any third party library like jQuery, you can try something like

    var parentNode = document.getElementById('list');
    parentNode.onclick=function(e){
        e = e || event;
        var target = e.originalTarget || e.srcElement;
        if(target.nodeName == "LI"){
            alert(target.innerHTML);
        }
    }
    

    The code make use of javascript event bubbling. It will help to reduce the number of click events registered in the page and help to increase the performance.

    But I would strongly request you to look into using some matured library like jQuery.

    Using jquery it will be as simple as

    $("#list").delegate("li", "click", function(){
        $(this).css('background-color', 'your color');
        $(this).css('color', 'your color');
    });
    

    I would recommend the usage of delegate since it will help to reduce the number of click event registered in the page.

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

Sidebar

Related Questions

I have multiple list items in an unordered list. Each list item looks like
Okay, Now I have an unordered list here: <ul id="mycustomid"> <li><a href="url of Item
I have an unordered list, each list item has an id (id=6~OriginalName) - when
I have an unordered list like this: <div class=blueBoxMid> <ul> <li>First item <em>This is
I have this unordered list <ul> <li>two</li> <li>three</li> </ul> Is there a way I
I'm trying to display an unordered list horizontally. In each list item, I have
I have an unordered list of items, I want to display each item as
I have a page with an unordered list built like this: <ul id='shows'> <div
I have a binary tree in unordered list that looks like this: <ul> <li>1
I have an unordered map: class O(val a: Int) Map[String, List[O]] which I'd 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.