Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why I can apply "this" ?

 
Nakata kokuyo
Ranch Hand
Posts: 467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good day,

Just trying out some sample for jQuery



Why i can't get the result of source location with "$(this)" when i used ".each" function in jQuery ?
I can only get the result by replace it using



Thanks in advance !
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The forum markup tags inside of code tags do not work. Look at the code!

jQuery does not have a .src, you would need to use .attr() to get to it.

Also why are you using var elems = document.getElementsByTagName("img"); when you can just do $("img") in jQuery?

Eric
 
Matthew Brown
Bartender
Posts: 4565
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
$(this) is a jQuery wrapped collection. Check the documentation and you'll see src isn't a property of that object.

If this represents the element, just try this.src or $(this).attr('src') (I haven't tested this, though).
 
Nakata kokuyo
Ranch Hand
Posts: 467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome, Thanks for explanation Eric and Matthew !

here my sample and it work under this.alt and $(this).attr('src') and $(this).prop("src");

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic