skiabox
skiabox

Reputation: 3507

Meaning of 'this' inside jQuery code

I am reading an excellent book about jQuery (Apress Pro jQuery) and I am a little confused about the use of 'this'. For example I am reading the following code :

<script type="text/javascript">
$(document).ready(function() {
    var isResult = $('img').is(function(index) {
        return this.getAttribute("src") == "rose.png";
    });
    console.log("Result: " + isResult);
  });
</script>

I am wondering at which object in this case 'this' refers to. Thank you.

Upvotes: 1

Views: 86

Answers (1)

Alex
Alex

Reputation: 35399

this in the "this" context is a reference to the DOM img element.

Upvotes: 5

Related Questions