From the given HTML, I am trying to extract the pText array, so that I end up with two <p> items (in this case), from which I can extract the two text strings "link test1" and "link test2", and pop an alert for each of them. Why doesn't the below script work?
HTML:
<div>
<p><a href='/'>link</a> test1</p>
<p><a href='/'>link</a> test2</p>
</div>
Javascript:
var pText = $('div').find('p');
for (i = 0; i < pText.length; i++) {
alert(pText[i].text());
}
$.map($('div p'), function(x) {return $(x).text()}).forEach(alert);