Reputation: 364
I have a click event listener as below:
$(".clickable").click(function (e) {
var results= $(e.currentTarget).closest('div.set').find('.clickable');
// returns
//[<label for="thumbnail" class="clickable">1 Malaysia</label>,
//<div class="thumbnail clickable">…</div>]
var label = $(results).find('label'); // returns [] (empty list)
}
My problem is, how can I select the label element from the results
list ? Thanks !
Upvotes: 3
Views: 63
Reputation: 9637
Try to use .filter()
instead of .find()
,
var label = results.filter('label');
.find()
will search for descendants, but here we are in need to filter out the required element from the collection, so use .filter(selector)
here.
And also you could have simply used as satpal said like,
var results= $(e.currentTarget).closest('div.set').find('label.clickable');
Upvotes: 2