unknown
unknown

Reputation: 866

Finding and Looping Through span Elements Inside (this) JQuery?

im trying to find every <span class ="anime_yellow">.. inside another <span class="toggle">, this is the code:

HTML:

    <span class="title_white">Menu 1</span>
      <span class="toggle">
     this is menu 1 i want to animate
          <span id="position" class="anime_yellow">Position</span>
        and
          <span id ="market" class="anime_yellow">market</span>.
      </span>
    <br><br>

    <span class="title_white">Menu 2</span>
      <span class="toggle">
     this is menu 2 i want to animate
          <span id="simple" class="anime_yellow">Simple</span>
        and
          <span id ="kool" class="anime_yellow">Kool</span>.
      </span>

The Javascript:

$(".toggle").hide();
$(".title_white").click(function() {
        $(".toggle").hide();
        $(this).next(".toggle").toggle("slow");
        // i want to find every span.anime_yellow inside the
        // THIS TOGGLE class and get its element ID
        // and then run function on the ID
        // animate(position) or animate(simple).

      });

im trying to use the jquery function .find(), but don't know where to start, this is the jsfiddle for it here: http://jsfiddle.net/wJJBa/2/

Upvotes: 0

Views: 1102

Answers (2)

Brad Bamford
Brad Bamford

Reputation: 3873

Edited with your Code Sample:

$(".toggle").hide();
$(".title_white").click(function() {
  $(".toggle").hide();
  var $toggle = $(this).next(".toggle");
  $toggle.toggle("slow");
  $toggle.find(".anime_yellow").each(function (i, e) {
    animate($(this).attr("id")); //Your ID is HERE
  });
});
function animate(divID){    
  alert(divID);
} 

Upvotes: 2

JMax
JMax

Reputation: 26591

Do you mean you want to do this: http://jsfiddle.net/sZUAE/1/

function animate(divID) {
    alert(divID);
}

$(".toggle").hide();
$(".title_white").click(function() {
    $(".toggle").hide();
    var $toggle = $(this).next(".toggle");
    $toggle.toggle("slow");
    $toggle.find(".anime_yellow").each(function(i, e) {
        animate(e.id);
    });
});

Upvotes: 2

Related Questions