Reputation: 169
This is my first question here. So be fair, please. :)
I don't get it.. I think my syntax isn't wrong but I only get an undefined object back from jquery. I try to pick an specific a tag element with the attribute-selector from jquery and after that I go down in the DOM till the last div before my img. At last I picked the img with the .find method.
Here is my code:
var cURL = $(this).find("img").attr("name");
console.log($("a[href=cURL] > div.image-box > div.image-content").find("img").attr("src"));
The var cURL
contains the right parameter as a string.
And the HTML/DOM:
<div class="product-wrapper...">
<div class="product-cell...">
<a class="image-wrapper" href="myArticle50">
<div class="image-box..">
<div class="image-content">
<img alt="..." src="media/testArticle/.../myArticle50.jpg">
</div>
</div>
</a>
....
</div>
</div>
In this case my var cURL would contain 'myArticle50' and I need the src from the img -> 'media/testArticle/.../myArticle50.jpg'. But I only get an undefined back.
May you see my failure in the code.. :/
Kind Regards.
Upvotes: 0
Views: 168
Reputation: 323
You have two mistakes, first:
This
console.log($("a[href=cURL] > div.image-box > div.image-content").find("img").attr("src"));
Should look like this
console.log($("a[href=" + cURL + "] > div.image-box > div.image-content").find("img").attr("src"));
and your class
<div class="image-box..">
Shouldn't have dots.
<div class="image-box">
Fix these, and your code should work fine and dandy.
Upvotes: 1