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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:42:11+00:00 2026-05-14T02:42:11+00:00

I have this href link with text either attivo or non attivo User can

  • 0

I have this href link with text either “attivo” or “non attivo”
User can set the item to ‘active’ or ‘closed’ in the database with an ajax request $.post()

I have 2 questions for these:

  1. I can’t get the reference to $(this) to work.. I tried it with a normal link and it works, but not wrapped in if/else??

  2. How can I prevent the user from clicking more than one time on the link and submitting several request? Is this a valid concern? Do I need some sort of a small timer or something?
    First I was thinking about a javascript confirm message, but that’s pretty annoying for this function..

HTML:

<dl id='album-list'>
<dt id="dt-2">some title</dt>
<dd id="dd-2">
    some description<br />
    <div class='links-right'>status: <a class='toggle-active' href='#'>non attivo</a></div>
</dd>
</dl>

<a class="test" href="#">test</a>

JS:

        $('dd a.toggle-active').click(function() {
            var a_ref = $(this);
            var id = a_ref.parent().parent().attr('id').substring(3);
            if (a_ref.text() == "non attivo") {
                var new_active = "active"; // for db in english
                $.post("ajax-aa.php", {album_id:id, album_active:new_active},
                function(data) {
                    // alert("success");
                    a_ref.text("non attivo"); // change href text
                });
            } else {                
                var new_active = "closed"; // for db in english
                $.post("ajax-aa.php", {album_id:id, album_active:new_active},
                function(data) {
                    // alert("success");
                    a_ref.text("attivo"); // change href text
                });
            }
            return false;
        });     

        $('a.test').click(function() {
            var a_ref = $(this);
            $.post("ajax-aa.php", {album_id:2, album_active:"active"},
            function(data) {
                a_ref.text("changed");
            });
            return false;
        })
  • 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-14T02:42:12+00:00Added an answer on May 14, 2026 at 2:42 am

    $(this) should refer to your a element inside the if/else, but not inside the callback function. The callback function is run in a different context, so inside the callback function

        function(date) { }
    

    this does not refer to the a element. this inside the callback function is not the same as this outside the callback function.
    Because the callback function is a closure though, it will keep a reference to your local variable a_ref.

    To prevent the user from clicking twice, add a class to the element

      $(this).addClass("hasbeenclicked")
    

    and in the click handler check whether this has been set and not do anything when it has:

      if ( ! $(this).is(".hasbeenclicked") ) {
      ....
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code: $('.access a').toggle(function() { $('link').attr('href', 'styles/accessstyles.css'); $('body').css('font-size', '16px'); }, function() {
I have this function: <script type='text/javascript'> $('#clicktogohome').live('click', function(){ history.pushState({}, '', this.href); popstate(this.href); return false;
so I have this code for tabs in jquery, the href is set to
I have index.php like this: <script type=text/javascript src=jquery-1.4.2.js></script> <script type=text/javascript src=ajax.js></script> <a href='one.php' class='ajax'>One</a>
Let's say I have this in a document: <entry> <link rel=replies type=application/atom+xml href=http://www.url.com/feeds/1/comments/default title=Comments/>
I have this atm: <a href=<%= Url.RouteUrl(UserDelete, new { userID = item.UserID }) %>
Suppose I have this: <ul id=menu> <li><a href=someplace>some text</a><li> ... </ul> I want to
I have this href defined in my markup: foreach (Car car in Model.Cars) {
I have this code: var fullpath = $(this)[0].src; var a = document.createElement('a'); a.href =
HI, I have this code for extracting the href and adding it to a

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.