How can I get the attribute of multiple dynamic elements?

Discussion in 'JavaScript' started by Airwalk Enterprise, Inc, Jun 2, 2011.

  1. #1
    So I have a while function in Php, and in each loop it echo's a div with a class that is dynamically fetched from a MYSQL database. So something like:

    while (blah blah) {

    echo "<div class=\"$fetch['something']\">content</div>";

    }

    Now in Javascript, I have something like:

    $('BLANKSPACE').mouseover(function (){ var star = $(this).index() + 1; $(this).parent().css("background-position","0 -" + (32 * star) + "px"); });

    ...........and so on.

    That code works fine if I have something like .class inside where it says BLANKSPACE, but what I want is to have the fetch data in there instead. Each fetch is different, making every classname different. The reason or this is that I am dynamically collecting the value from these classes and storing/querying as user data (for a rating system). So for instance, $fetch['something'] may include the persons name.

    Now I know how to get the elements id, but how could I include a Javascript loop at the bottom of the page where it collects the value of the all the classes where the div id is something constant and static like "rating", and puts all those classes into my Javascript something like:

    "$('.classfromfirstloop', '.classfromsecondloop', '.classfromthirdloop').mouseover(function (){ var star = $(this).index() + 1; $(this).parent().css("background-position","0 -" + (32 * star) + "px"); });

    etc, etc, applying my code to all of those classes. Because the classes are originally fetched data, the values would be unknown beforehand, so I would like the Javascript to get the attributes values after Php echos them in it's loop.

    Thanks in advanced.