aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Why I can apply Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Why I can apply "this" ?" Watch "Why I can apply "this" ?" New topic
Author

Why I can apply "this" ?

Nakata kokuyo
Ranch Hand

Joined: Apr 13, 2005
Posts: 442
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Apr 06, 2010
Posts: 4490
    
    8

$(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

Joined: Apr 13, 2005
Posts: 442
Awesome, Thanks for explanation Eric and Matthew !

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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why I can apply "this" ?