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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:28:39+00:00 2026-05-28T18:28:39+00:00

In this script, I’m fetching a load of data from a MySQL aray, and

  • 0

In this script, I’m fetching a load of data from a MySQL aray, and adding in a little favourite button on each array of returned data, the code for that is

...php while code to fetch array...
...more output...
<a class="favlink" id="'.$row['id'].'">favourite</a>
..more output...

and from that, I’ve used this bit of jQuery to run a PHP script:

<script>
$(function() {
    $(".favlink").bind("click", function() {
        $.ajax({
            type: "GET",
            data: "v="+$(this).attr("id"),
            url: "fav.php",
            success: function(data) {
            alert('asf');
            }
        });
    });
});
</script>

That works fine, but what I actually want to do, is change the success to something like this:

success: function(data) {
$(this).html("<font color='#ccc'><a href='#'>favourited</a></font>");
}

And, that didn’t work!

Is there any way I can change the clicked favourite link to a different font color / and change the text from ‘favourite’ to ‘favourited’?

I assume the ‘this’ property is no longer ‘this’ on success for some reason, but I’m not sure?

Thank You!

  • 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-28T18:28:40+00:00Added an answer on May 28, 2026 at 6:28 pm

    You have to define the context of the ajax. See the docs from Jquery site:

    contextObject This object will be made the context of all Ajax-related
    callbacks. By default, the context is an object that represents the
    ajax settings used in the call ($.ajaxSettings merged with the
    settings passed to $.ajax). For example specifying a DOM element as
    the context will make that the context for the complete callback of a
    request, like so:

    $.ajax({
      url: "test.html",
      context: document.body,
      success: function(){
        $(this).addClass("done");
      }
    });
    

    So in your’s case I think this is what you need:

      $.ajax({
      url: "test.html",
      context: this,//OR: $(".favlink")[0], // Depends on your scope.
      success: function(){
          $(this).html("<font color='#ccc'><a href='#'>favourited</a></font>");
      }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This script is supposed to get the current popularity from Mysql, add one digit
Why isn't this script working? $(function() { var isbn = $('input').val(); $('button').click(function() { $(#data).html('<iframe
This script extracts data from check boxes in order to determine the information a
I have this script: select name,create_date,modify_date from sys.procedures order by modify_date desc I can
This script is to connect to different servers and copy a file from a
This script strips the timezone from an email's Date fields: #!/bin/sed -rf s/(^Date: (Sun|Mon|Tue|Wed|Thu|Fri|Sat),.*[0-9][0-9]:[0-9][0-9]:[0-9][0-9])
I have this script- import lxml from lxml.cssselect import CSSSelector from lxml.etree import fromstring
This script is supposed to to get a multidimensional array and iterate through the
This script is run from within a directory of OGG files. cd c:\dirWithOGG for
This first script gets called several times for each user via an AJAX request.

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.