Solved

Jquery - what was the id that triggered the event

Posted on 2014-09-09
3
155 Views
Last Modified: 2014-09-09
Hi E's,
I have this code:
$("#one, #two").focus(function(){
    alert($(this).is(":focus"));
    }); 

Open in new window

And I have to know what was the id that triggered the event.
The output of this code is false!
How I know if it is the #one or the #two id that triggered the event?

The best regards, JC
0
Comment
Question by:Pedro Chagas
3 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40312862
change your alert to :
alert($(this).id);

Open in new window

to see what you get
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40312874
$("#one, #two").focus(function(){
    alert($(this).attr("id"))
    alert($(this).is(":focus"));
}); 

Open in new window

0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 40313285
Hi Randy, the output is "undefined".
Thanks for trying to help.

The best regards, JC
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now