user8236024
user8236024

Reputation:

nodejs cheerio selecting child element inside an each loop

I'm trying to select the strong a tags that's inside the .info class

$(".info").each(function(i, item){
    console.log($(this).children("strong a").text())
});

it's selecting the info class correctly, just not the strong a

enter image description here

Upvotes: 8

Views: 17614

Answers (2)

Krishnadas PC
Krishnadas PC

Reputation: 6519

Inside a loop, you can also use like this

$(".info").each(function(i, item){
   $(this).find("strong a").text();
});

Upvotes: 5

Jiby Jose
Jiby Jose

Reputation: 3845

You should be able to do

$(".info").each(function(i, item){
    console.log($("strong a", item).text())
});

Upvotes: 17

Related Questions