Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

María Pérez de Arrilucea
6,490 PointsMethod 'isValidEmail', why $(this) is not valid?
Hi, I know what is the correct answer, but I would like to know why the following code is not correct:
function isValidEmail(email) {
return $(this).indexOf("@") != -1;
};
I thought $(this) would be related to the email.
Thanks a lot!
2 Answers

Matt Campbell
9,767 PointsHi, no.
$(this) relates to the element that the function is relating to. So if you had a click function that was something like
$('#activator').click(function(){
$(this).animate({...});
});
When you click on #activator, the animation would act upon #activator, QED $(this).

María Pérez de Arrilucea
6,490 PointsThanks a lot Matthew! I understand it perfectly now :)