Answer the question
In order to leave comments, you need to log in
Jquery selector not working?
I've been suffering for half an hour, please help.
The structure is as follows: <img src="jpg"
When I click on tr, I try to get the src attribute from the image
var image = $(this).children("img").attr("src");
Tried the following:
Assigned td class image
var image = $(this).children(".image img").attr("src");
Directly
var image = $(this).children("img").attr("src");
Assigned img class image
var image = $(this).children(".image").attr("src");
var image = $(this).children("td .image").attr("src");
var image = $(this).children("td img").attr("src");
None of this works. CHDNT?
Answer the question
In order to leave comments, you need to log in
.children() is an immediate child, so $(this).children('td') will work, but $(this).children('img') won't because tr has only td as an immediate child.
Also, the argument of the children method is a filter.
Use .find(), don't miss it :)
var image = $(this).children("td").children("img").attr("src");
Tried this right after posting the question. Earned. Horror =)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question