This is one easy (I hope) question which is bugging me for years. How do you get element that fired event which triggered the ajax request? Here is an example:
<button id="clickme">Click me</button>
$("#clickme").click(function(e){
var i_need_this=e.target;
alert(i_need_this); //nice!
$.ajax({
url:'http://echo.jsontest.com/',
type: 'GET',
success: function( data, status, jqXHR ) {
alert('success');
//console.log( ??? ); Get i_need_this from somewhere?
}
});
})
Live: http://jsfiddle.net/8F3u2/
Thanks in advance!
You can use context
param here:
$.ajax({
url:'http://echo.jsontest.com/',
context:this, // <------this is the cliked button
type: 'GET',
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With