Quantcast
Channel: jQuery loop through child elements to get attr value - Stack Overflow
Viewing all articles
Browse latest Browse all 4

jQuery loop through child elements to get attr value

$
0
0

I am trying to loop through an elements children to get there attr value. My HTML looks like this:

<div class="deal"><img src="/images/deals/xbox-one500-gb-black.png" alt="Xbox One 500 GB Black box art/packaging" title="Xbox One 500 GB Black" height="60" width="40" class="console" /><img src="/images/deals/xbox-one-additional-controller.png" alt="Additional Controller box art/packaging" title="Additional Controller" height="60" width="40" /><img src="/images/deals/xbox-one-fifa-15.png" alt="FIFA 15 box art/packaging" title="FIFA 15" height="60" width="40" />              </div>

I would like to get the title attr off all items and combine into 1 title.

here is my script:

$(".deal").each(function() {  var test = $(this).attr('title');}console.log(test);

Am i approaching this in the right way?


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images