deviant deviant - 4 years ago 141
Javascript Question

Jquery for each in HTML string

I have an HTML string, which I get from using

getJSON
method. I want to iterate through this whole string, find all divs with class
product-review
and push its content to my array. What is the best way to do this?

Answer Source

1st : you need to select the 'div.product-review' by using .find()

$(response).find('div.product-review')

2nd: you need to loop through them and push its content to the array

var contentarray = [];
$(response).find('div.product-review').each(function(){
    var ThisIt = $(this);
    contentarray.push(ThisIt.text());
});
console.log(contentarray);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download