I need help on understand how the $(this) work exactly because i can't bring this simple code to work:
HTML:
<img style="cursor:pointer;" onclick="openfullsize();" src="/customimage/test.png"/> JS:
function openfullsize(){ var path = $(this).attr("src"); alert(path); } I wonder if there is anything i'm doing wrong or if I just don't understand how $(this) behave. $(this) should refer to the element from which it is invoked, right? in this case, it would be my img.
This should alert the content of the src attribute but it is undefined.
I would like this to be in Jquery please.
Thanks for your help and here is the JsFiddle
thisis window, so there is that. jQuery in your fiddle was never included either. Basically, you need to just add jquery, avoid inlining your event handler, and once you have converted to unobtrusive with a jquery or native handler,thiswill properly apply to the element and vuala, src will be available.