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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:59:36+00:00 2026-05-28T14:59:36+00:00

<ul class=Buttons> <li><a href=# onclick=myFunc(); return false;>Accept</a></li> <li><a href=# onclick=myFunc(); return false;>Reject</a></li> <li><a href=#

  • 0
<ul class="Buttons">
    <li><a href="#" onclick="myFunc(); return false;">Accept</a></li>
    <li><a href="#" onclick="myFunc(); return false;">Reject</a></li>
    <li><a href="#" onclick="myFunc(); return false;">On Hold</a></li>
    <li><a href="#" onclick="myFunc(); return false;">Completed</a></li>
</ul>

In my script.js:

var myFunc = function () {
    // I want to get the Text of the link e.g. if the first list item link is
    // clicked, store "Accept" in a variable.
};

How can I achieve this?

  • 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-28T14:59:37+00:00Added an answer on May 28, 2026 at 2:59 pm

    You could pass the current link as argument to the function:

    <ul class="Buttons">
        <li><a href="#" onclick="myFunc(this); return false;">Accept</a></li>
        <li><a href="#" onclick="myFunc(this); return false;">Reject</a></li>
        <li><a href="#" onclick="myFunc(this); return false;">On Hold</a></li>
        <li><a href="#" onclick="myFunc(this); return false;">Completed</a></li>
    </ul>
    

    and then use the innerHTML property to fetch the text inside:

    var myFunc = function (link) {
        alert(link.innerHTML);
    };
    

    UPDATE:

    I haven’t noticed that actually your question is tagged with jQuery. In this case I would recommend you unobtrusively subscribing to the click handler:

    <ul class="Buttons">
        <li><a href="#">Accept</a></li>
        <li><a href="#">Reject</a></li>
        <li><a href="#">On Hold</a></li>
        <li><a href="#">Completed</a></li>
    </ul>
    

    and in a separate js file:

    $(function() {
        $('.Buttons a').click(function() {
            alert($(this).text());
            return false;
        });
    });
    

    UPDATE 2:

    It was asked how to assign those click handlers if those anchors were dynamically generated. So let’s assume that you start with the following markup:

    <ul class="Buttons"></ul>
    

    and then when some event happens (click or something) you add an anchor dynamically:

    $('<li/>', {
        html: $('<a/>', {
            href: '#',
            text: 'some text ....',
            click: myFunc
        })
    }).appendTo('.Buttons');
    

    where you have defined myFunc somewhere:

    var myFunc = function() {
        alert($(this).text());
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var linksInCategory = document.id($('.CategoryTreeLabel').href); var randomLinkArray = new Array(linksInCategory); //CategoryTreeLabel is the class all
Can someone tell me why this is not working: <button class=btn danger id=delete onclick=return
I'm currently using the following code for my read more buttons: $(document).ready(function() { $("a.more-link").attr("href",
My onclick function works beautifully when i pass one variable and doesn't respond once
I have some html to popup a jQuery UI modal: <a href=my/url class=popup>Click me</a>
Hey I have my code as follows at the moment <script type=text/javascript> var activeTabId
I have <a href=test.php?id=2 class=confirm_delete>Click to proceed</a> and following javascript. When I click on
I have this jquery script that refreshes a div tag on my page: $(function()
I have inherited a c# class 'Button' (which I can't change) which clashes with
Button class: class SubmitButton extends JButton implements ActionListener { public SubmitButton(String title){ super(title); ....

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.