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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:26:40+00:00 2026-05-11T20:26:40+00:00

I have a list of items <ul class=list> <li> <a href=#Course1 class=launch onclick=alert(‘event 1’)>event

  • 0

I have a list of items

<ul class="list">
    <li>
        <a href="#Course1" class="launch" onclick="alert('event 1')">event 1</a>
    </li>
    <li class="alt">
        <a href="#Course2" class="launch" onclick="alert('event 2')">event 2</a>
    </li>
    <li>
        <a href="#Course3" class="launch" onclick="alert('event 3')">event 3</a>
    </li>
    <li class="alt">
        <a href="#Course4" class="launch" onclick="alert('event 4')">event 4</a>
    </li>
</ul>

I want to be able to assign the onclick of the link to the onclick of the li aswell

My attempt so far is one click behind (as I am assigning the script to the onclick rather than executing the script)

$('.list li').click(function() {
    var launch = $('a.launch', this);
    if (launch.size() > 0) { this.onclick = launch.attr('onclick'); }
});

Thanks in advance
Tim

  • 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-11T20:26:40+00:00Added an answer on May 11, 2026 at 8:26 pm

    building on @Thomas Stock’s answer the following code prevents double execution on clicking on link instead of li. (got it from here jQuery site)

    $(document).ready(function() {
    
        $('ul.list li').click(function(e) {
            var $target = $(e.target);
            if(!$target.is("li")) //magic happens here!!
            {
                return;
            }
    
            var launch = $('a.launch', this);
            if (launch.size() > 0) 
            { 
              eval(launch[0].onclick());
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 237k
  • Answers 237k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well, the app itself would run but the major obstacle… May 13, 2026 at 6:32 am
  • Editorial Team
    Editorial Team added an answer Assuming you mean a UDP/ICMP ping just to see if… May 13, 2026 at 6:32 am
  • Editorial Team
    Editorial Team added an answer If you just need to display it on the client,… May 13, 2026 at 6:32 am

Related Questions

I have a list of items <ul class=list> <li> <a href=#Course1 class=launch onclick=alert('event 1')>event
Ok..so I'm a nOOb with jquery. I have a dynamically created list of items
Is it possible to re-use a client-template using asp.net ajax 4.0 client templates? I
I have a list of items which I want the user to be able
I have a list of items that I want to be laid out horizontally.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.