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!
You have to define the
contextof theajax. See the docs from Jquery site:So in your’s case I think this is what you need: