Getting the ID of the element that fired an event using JQuery

Getting the ID of the element that fired an event using JQuery

Hello sir

I want to know-Is there any way to get the ID of the element that fires the event? Please mention the code with your reply. This will make easy for me to understand the concept.

Thanks in advance

View Answers

December 11, 2010 at 4:38 PM

Dear friend

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

Use the following snippet in your code :

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









Related Tutorials/Questions & Answers:
Getting the ID of the element that fired an event using JQuery
Getting the ID of the element that fired an event using JQuery  Hello sir I want to know-Is there any way to get the ID of the element that fires... friend In jQuery event.target always refers to the element that triggered
JQuery-event working new element
JQuery-event working new element  I want to know- why not an event(in JQuery) works on my created element through jQuery
Advertisements
Test hidden element using JQuery
Test hidden element using JQuery  Suppose i have an element which i am hiding and showing, using .hide(), .show() or .toggle().How do you test to see... using following code snippet :ADS_TO_REPLACE_1 $(element).is(":visible") Hope
Using the jQuery event object
Using the jQuery event object       Using the jQuery event object JQuery... to these standards, this system normalize the event object. jQuery. Event
Bind custom event with an element using 'bind'
Bind custom event with an element using 'bind' In this tutorial, we will discuss about how to bind a user define event with an element using 'bind ' function of jQuery. In this example ,  we are firing an user
Position one element relative to other using JQuery.
Position one element relative to other using JQuery.  Hello Sir...: absolute; display: none;" id="menu"> <!-- menu stuff in here --> </div> <div id="placeholder">Hover over me to show the menu here</div>
Creating, getting, and setting content using jQuery
Creating, getting, and setting content using jQuery... content using jQuery Using jQuery , you can add(create) html content... You can get the html by using jQuery and also can modify
JQuery-Disabling element in JQuery.
JQuery-Disabling element in JQuery.   How can we enable/disable an element in JQuery
Getting the last inserted id using jsp
Getting the last inserted id using jsp  Pls how can i retrieve the last inserted id after submitting a form to mysql using jsp
JQuery-confirming exsistance of an element.
JQuery-confirming exsistance of an element.  Hi there, How do I test whether an element exists in jQuery?   You can check existance of an element in jQuery using length property of the jQuery collection
JQuery-Selecting class or ID
JQuery-Selecting class or ID  Hi Guys, I am new to JQuery. I am getting little trouble in selecting an item using class or ID in jQuery?   Given below code selects an element of id name "element1
JQuery-Selecting class or ID
JQuery-Selecting class or ID  Hi Guys, I am new to JQuery. I am getting little trouble in selecting an item using class or ID in jQuery
jQuery change event
jQuery change event In this tutorial , we will discuss about 'change' event of jQuery. In given below example ,the change event is fired when there is change in the element (on which event is set).When the second option
jQuery bind event
jQuery bind event In this tutorial, we will discuss about how to bind multiple events with an element using jQuery. In this example, a paragraph binds with multiple events like click, mouseenter mouseleave,  dblclick etc using
Selenium webdriver - Getting Xpath for element in IE
Selenium webdriver - Getting Xpath for element in IE   How to get Xpath for element in IE
Selenium webdriver - Getting Xpath for element in IE
Selenium webdriver - Getting Xpath for element in IE   How to get Xpath for element in IE
jquery href onclick event
jquery href onclick event  jquery href onclick event   $('a').click(function (event) { event.preventDefault(); //here you can also do all sort of things });   <script type="text/javascript
JQuery date change event
JQuery date change event  JQuery date change event I have been designing a date form in HTML and JQuery, wher i need two different date vales start date and end date for any event. I have already writen a function that allows
The scroll browser event of jQuery
The scroll browser event of jQuery In this tutorial ,we will print message on browser's window scrolling using scroll browser event of jQuery. In this example, some paragraphs are written , when we scroll down, a message
jQuery blur event
jQuery blur event In this tutorial , we will discuss how to handle blur event of jQuery. In the below example , there are two input field ,when you click... on any other elements in the page ,it shows an alert box .The blur event is sent
set the focus on an element using Javascript
set the focus on an element using Javascript  How to set the focus on an element using Javascript
Understanding the jQuery event handling mechanism
Understanding the jQuery event handling mechanism       Understanding the jQuery event handling mechanism First of all , you need to know -What is an event
Selecting element using jQuery.
Selecting element using jQuery In this tutorial , we will discuss about... to: Select the element by id Apply the different operations, interceptors, css... element in HTML page and perform the different operations using JavaSript
jQuery focus event
jQuery focus event In this tutorial, we will discuss about how to handle focus event of jQuery. In this example, 2 text field and one password field...()' method of jQuery.   focusEvent.html <!DOCTYPE html>
jQuery '.live' & '.die' Mouse events
jQuery '.live'  & '.die' Mouse events In this tutorial ,we will discuss about how to  remove an event using 'die' mouse event of jQuery. In this Example, we removes the 'click' event
'key down' mouse event of the jQuery
'key down' mouse event of the jQuery In this tutorial ,we will display ASCII value using "key down" method of jQuery. In this example...;/head> <body> <input id="whichkey" value="
Vertical news slider using jquery
Vertical news slider using jquery  how to creatw vertical news slider using jquery Sorry for wrong category but i cant get my jquery category
Show Limited Data Using jquery
Show Limited Data Using jquery  How to show limited results in JQuery... it using JQuery?   See the JQuery example to show the limited fetch results in JQuery. var comments = $('.description_text').size(); if (comments >
jQuery 'submit' form event
jQuery 'submit' form event In this tutorial, we will discuss about the  'submit' form event of jQuery. In this example... when "submit" event return 'true' to 'form'
jQuery - jQuery Tutorials and examples
Binding and unbinding events Event helpers Using the jQuery event... Demos:ADS_TO_REPLACE_2 We have created many examples of using jQuery. View the demo's here. Learn jQuery step by step using the following tutorials
Form validation Using Jquery Plugin
Form validation Using Jquery Plugin  Hello sir I want to implement form validation using JQuery Plug-in. My code is : <html> <style type...="label">Name *</span><input type="text" name="name" id="namei"/><
Html form validation using jquery
Html form validation using jquery  Hi i am using form with html. Form elements like textbox, radio,checkbox,listbox i was used now how to validate the elements using submit jquery option
HTML form validation using jquery
HTML form validation using jquery  Is there any way for validating html elements common under a class by giving its class name in jquery validation code..that means validating all elements by using its class name if those
Using the jQuery Transform plug-in(XSLT)
Using the jQuery Transform plug-in(XSLT)       Using the jQuery Transform plug-in(XSLT... Language Transformations ). The jQuery Plugin we are using
Getting The XML Root Element
Getting The XML Root Element      ... using getDocumentElement() method. To get the root element use the getNodeName...; root element from the XML document.  The JAXP (Java APIs for XML Processing
Disabling submit button using jQuery
Disabling submit button using jQuery  Hello Sir I want to know - is there any way or approach to disable client side form's "Submit" button. Please give code also.ADS_TO_REPLACE_1   For all submit buttons, via JQuery
application using AJAX and JQuery and also use JSP
application using AJAX and JQuery and also use JSP   i need create an application using AJAX and JQuery and also use JSP
Getting Started with jQuery
jQuery: jQuery:  jQuery is a JavaScript library which accentuates interaction between JavaScript and HTML. jQuery helps programmers to keep the program simple and concise. jQuery library simplifies the process of traversal
Auto select cell on mouse hover using 'hover' mouse event
Auto select cell on mouse hover using 'hover' mouse event In this tutorial, we will discuss about how to highlight Table's cell on mouse hover using jQuery 'hover' mouse event. In this example, a table is given
Find Browser & it's version using jQuery
Find Browser & it's version using jQuery  Hi sir I heard that JQuery have some method which can be used to find the Browser name & its version. I need the code which checks the browser and if it is "Mozilla", it will show
How to write a search functionality using javascript/jquery
How to write a search functionality using javascript/jquery   How to write a search functionality using javascript/jquery for ex: im searching "s" names it wil display "s" names
Using redirect element & wild card
Using redirect element & wild card  ...; is an optional element which can be used to specify that the response is generated by the new view using redirect response rather than rendering the response
delete row using id
delete row using id  package pkg2; import org.hibernate.Query; import... = "delete from Insurance insurance where id = 2"; Query query = sess.createQuery...()); } } } this is the code m using . Error is -query must begin with SELECT or FROM
Implementing Digits restriction Using JQuery
Implementing Digits restriction Using JQuery  Hi Sir I have..." id="quantity" /></div> I want to implement two things : 1.... Please provide code.   You can implement these two things using ASCII code
Using the QUnit to test jQuery application
Using the QUnit to test jQuery application       Using the QUnit to test jQuery application Using Qunit , testing of JQuery become very easy and efficient
Crop image Using JQuery, servlet or JSP.
Crop image Using JQuery, servlet or JSP.  Hi sir I need the code of Cropping image using JQuery with the help of servlet or JSP. I need both the code Client side as well as of server side. Please Help me
Display message on scroll Event
Display message on scroll Event In this tutorial, we will discuss about how to display message on scrolling of text area using jQuery scroll event...;/head> <body> <div id="target" style="overflow: scroll
Replace broken Image using JQuery
Replace broken Image using JQuery  Sir My web page contains a lot of images. But when it will not loaded properly, it shows a broken image. How can I fix it so that broken image will be replaced by error image automatically
Hide boxes by clicking on it using jQuery
Hide boxes by clicking on it using jQuery In this tutorial , we will discuss about how to hide boxes by clicking on it using jQuery. In the given below.... These hide action is due to event click. jqHideboxonclick.html  
jQuery Features
to them using methods of jQuery. It is using CSS 3.0 syntax which provide us freedom to select one or more elements. Using CSS , you can select element... index.ADS_TO_REPLACE_2 Events  jQuery provide simplified event handling

Ads