views:

111

answers:

2

Hi all, If I am selecting as follows:

  $('li',"#container").draggable({
    /* blah */
 });

How do I get the individual class attributes for those elements selected so that I can something along the lines of

    $('li',"#container").draggable({
      /* blah */
   }).attr("name", "insert name of individual img");

The markup is as follows:

  <ul id="container">
        <li class="blah">
          <img src="" class="update" name="I Want This" width="40" height="40" />
        </li>
        <li class="blah">
          <img src="" class="update" name="I Want this too" width="40" height="40" />
        </li>
  </ul>
+4  A: 

You probably have to use each() for this:

$("li", "#container").draggable({
  // ...
}).each(function() {
  $(this).attr("name", $(this).find("img").attr("name"));
});
cletus
+4  A: 

You can use the jQuery.each() method to iterate over the collection of jQuery Objects

$('li',"#container").draggable({
    /* blah */
}).each(function() {
    $(this).attr("name", "insert name of individual img");
});
Jon Erickson
Thank you once again for your help!
Rio