views:

34

answers:

4

I have an image, onclick on wich i make some ajax requests. i need to pass a variable from $_GET[] to my onclick function, so i deside to do the following

<img id="img1" class="<?=$_GET['value']"?> />

and jquery

$("#img1").click(function()
{
how can i get the class value here???
});

Thanks

+3  A: 

pretty easily

$(this).attr('class');

FYI there are also dedicated class methods in jquery, such as addClass(), removeClass(), hasClass() & toggleClass()

Ben Rowe
@Ben Rowe :/ thanks man
Syom
@Syom - protip - you don't need the full name with `@`, just the first word (as in @Ben) is sufficient for generating notifications.
Anurag
A: 
$(this).attr("class");

Also note that $("#img") wont really catch anything. These two, however, will:

$("img")
$("[id^=img]")
Emil Vikström
A: 

You can use $(this).attr("class");.

Unrelated: Undoubtedly, someone is going to comment on my answer to recommend caching the result of $("#img").

icktoofay
you should cache the result of `$("#img")` :P
Anurag
of course you should :DDD
Syom
A: 
$(this).attr('class')
nil