tags:

views:

32

answers:

3

I have a collection of divs on a page with the same class name.

<div class="ProductName">Product Foo</div>
<div class="ProductName">Product Bar</div>

I would like to be able to retrieve, iterate through and this case alert the ProductName div's contents.

Currently I can retrieve and iterate, but I can't alert the individual contents.

var ExistingProductNamesOnscreen = $.makeArray($(".ProductName"));
$.each(ExistingProductNamesOnscreen, function (key, val) {
    alert(*ProductName contents*);
});
A: 

did you try

alert ($(this).text());

or

alert ($(this).html());

?

(The first should alert text contents, while the latter also any tags found in particular div)

Adam Kiss
+1  A: 
$(".ProductName").each(function ()
{
    alert($(this).text());
});
bang
+3  A: 
$(".ProductName").each(function(k, v) {
    alert($(v).text());
});
harpax