In JQuery, it seems that $(this) only works locally.
give a quick example:
$(".someClass .type1").click(function(){
$(".someClass .type1").html("<img src='image/2.png'>");
$(this).html("<img src='images/img.png'>");
});
$(".otherClasses").click(function(){
$(".otherClasses .type1").html("<img src='image/2.png'>");
$(this).html("<img src='images/img.png'>");
});
Ideally, I want to write a function like this:
function changeImg () {
$(this).html("<img src='images/img.png'>");
}
And then call changeImg() under the jquery click functions like:
$(".someClass .type1").click(function(){
$(".someClass .type1").html("<img src='image/2.png'>");
changeImg();
});
However, in this way, the $(this) will be 'undefined' instead of the one that is clicked anymore. Is there a way to make it available like a global variable?
Thank you!