tags:

views:

22

answers:

2

I have the following timer which periodically updates my page:

var refreshId = setInterval(function() {
    $(".content").each(function(i) {
        // Do stuff
        $(this).each(function(i) {
          // issue here
        });
    });
}, 10000);

Within the nested foreach loop, I would like to extract only images, so essentially, I would want to match this > .icons > .img, as my images are inside of a div of class "icons".

The markup for the section would look like the following:

       <div class="content">
            <div></div>
            <div class="icons">
                <img id="dynamicImage12345" src="#">
            </div>
        </div>

How can I accomplish this?

+1  A: 

You need this line there:

$("div.icons > .img", $(this)).each(function() {
    // your code to for images
});

It is assumed that you are using img class for your images as can be seen from your code. If you are not using a class, you can try this instead:

$("div.icons > img", $(this)).each(function() {
    // your code to for images
});

So it becomes:

var refreshId = setInterval(function() {
  $(".content").each(function(i) {
    // Do stuff
    $("div.icons > img", $(this)).each(function() {
      // your code to for images
    });
  });
}, 10000);
Sarfraz
I added the sample markup for a more clear picture. Still the same answer?
George
A: 

If I'm reading this right, what you want is this:

var refreshId = setInterval(function() {
    $(".content").each(function(i) {
        // Do stuff
        $(".icons > .img", this).each(function(i) {
          // issue here
        });
    });
}, 10000);
R. Bemrose