Skip to main content
Remove unnecessary quotes.
Source Link
Jack Bashford
  • 44.3k
  • 11
  • 56
  • 84

In jQuery event.target always refers to the element that triggered the event, where 'event'event is the parameter passed to the function. http://api.jquery.com/category/events/event-object/

$(document).ready(function() { $("a").click(function(event) { alert(event.target.id); }); }); 

Note also that 'this'this will also work, but that it is not a jQuery object, so if you wish to use a jQuery function on it then you must refer to it as '$$(this)', e.g.:

$(document).ready(function() { $("a").click(function(event) { // this.append wouldn't work $(this).append(" Clicked"); }); }); 

In jQuery event.target always refers to the element that triggered the event, where 'event' is the parameter passed to the function. http://api.jquery.com/category/events/event-object/

$(document).ready(function() { $("a").click(function(event) { alert(event.target.id); }); }); 

Note also that 'this' will also work, but that it is not a jQuery object, so if you wish to use a jQuery function on it then you must refer to it as '$(this)', e.g.:

$(document).ready(function() { $("a").click(function(event) { // this.append wouldn't work $(this).append(" Clicked"); }); }); 

In jQuery event.target always refers to the element that triggered the event, where event is the parameter passed to the function. http://api.jquery.com/category/events/event-object/

$(document).ready(function() { $("a").click(function(event) { alert(event.target.id); }); }); 

Note also that this will also work, but that it is not a jQuery object, so if you wish to use a jQuery function on it then you must refer to it as $(this), e.g.:

$(document).ready(function() { $("a").click(function(event) { // this.append wouldn't work $(this).append(" Clicked"); }); }); 
edited body
Source Link
samjudson
  • 57k
  • 7
  • 61
  • 69

In jQuery event.target always refers to the element that triggered the event, where 'event' is the parameter passespassed to the function. http://api.jquery.com/category/events/event-object/

$(document).ready(function() { $("a").click(function(event) { alert(event.target.id); }); }); 

Note also that 'this' will also work, but that it is not a jQuery object, so if you wish to use a jQuery function on it then you must refer to it as '$(this)', e.g.:

$(document).ready(function() { $("a").click(function(event) { // this.append wouldn't work $(this).append(" Clicked"); }); }); 

In jQuery event.target always refers to the element that triggered the event, where 'event' is the parameter passes to the function. http://api.jquery.com/category/events/event-object/

$(document).ready(function() { $("a").click(function(event) { alert(event.target.id); }); }); 

Note also that 'this' will also work, but that it is not a jQuery object, so if you wish to use a jQuery function on it then you must refer to it as '$(this)', e.g.:

$(document).ready(function() { $("a").click(function(event) { // this.append wouldn't work $(this).append(" Clicked"); }); }); 

In jQuery event.target always refers to the element that triggered the event, where 'event' is the parameter passed to the function. http://api.jquery.com/category/events/event-object/

$(document).ready(function() { $("a").click(function(event) { alert(event.target.id); }); }); 

Note also that 'this' will also work, but that it is not a jQuery object, so if you wish to use a jQuery function on it then you must refer to it as '$(this)', e.g.:

$(document).ready(function() { $("a").click(function(event) { // this.append wouldn't work $(this).append(" Clicked"); }); }); 
added 52 characters in body
Source Link
samjudson
  • 57k
  • 7
  • 61
  • 69

In jQuery event.target always refers to the element that triggered the event, where 'event' is the parameter passes to the function. http://api.jquery.com/category/events/event-object/

$(document).ready(function() { $("a").click(function(event) { alert(event.target.id); }); }); 

Note also that 'this' will also work, but that it is not a jQuery object, so if you wish to use a jQuery function on it then you must refer to it as '$(this)', e.g.:

$(document).ready(function() { $("a").click(function(event) { // this.append wouldn't work $(this).append(" Clicked"); }); }); 

In jQuery event.target always refers to the element that triggered the event, where 'event' is the parameter passes to the function.

$(document).ready(function() { $("a").click(function(event) { alert(event.target.id); }); }); 

Note also that 'this' will also work, but that it is not a jQuery object, so if you wish to use a jQuery function on it then you must refer to it as '$(this)', e.g.:

$(document).ready(function() { $("a").click(function(event) { // this.append wouldn't work $(this).append(" Clicked"); }); }); 

In jQuery event.target always refers to the element that triggered the event, where 'event' is the parameter passes to the function. http://api.jquery.com/category/events/event-object/

$(document).ready(function() { $("a").click(function(event) { alert(event.target.id); }); }); 

Note also that 'this' will also work, but that it is not a jQuery object, so if you wish to use a jQuery function on it then you must refer to it as '$(this)', e.g.:

$(document).ready(function() { $("a").click(function(event) { // this.append wouldn't work $(this).append(" Clicked"); }); }); 
deleted 40 characters in body
Source Link
Dave Jarvis
  • 31.3k
  • 43
  • 186
  • 326
Loading
Source Link
samjudson
  • 57k
  • 7
  • 61
  • 69
Loading