<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('div.testClass').each(function(i) {
            $(this).attr('id', 'test' + i)
        });
    });
</script>

<div class="testClass">A</div>
<div class="testClass">B</div>
<div class="testClass">C</div>

$('div.testClass').each(function(i) <-- will loop over each instance of a
div with the class "testClass".

For each iteration of the loop, 'i' is the loop index (e.g. for 1st
iteration its value is "1", second iteration, "2", etc).

So for each loop, you set the "id" attribute of the div being looped over to
"testi" (where "i" represents a number).

You'll end up with the first div having an ID of "test1", the second an id
of "test2", etc.

If you run the code above in Firefox using Firebug, you should be able to
see the attributes in the code.

On Sat, Dec 5, 2009 at 4:42 AM, kbuntu <i...@teevotee.com> wrote:

> I'm a designer and totally lost when it comes to php or java script.
> Perhaps somebody can help me.
>
> I have several images when hover over it will display a DIV called
> testing. The content is dynamically generated by wordpress. My problem
> is when I hover over an image it displays all the div's with the class
> "testing". What I need to do is somehow generate a random id by
> Jquery.
>
>
> <script type="text/javascript">
>    $(document).ready(function() {
>        var hide = false;
>        $(".rss-link").hover(function(){
>            if (hide) clearTimeout(hide);
>            $(".testing").fadeIn();
>        }, function() {
>            hide = setTimeout(function() {$(".testing").fadeOut
> ("slow");}, 500);
>        });
>        $(".testing").hover(function(){
>            if (hide) clearTimeout(hide);
>        }, function() {
>            hide = setTimeout(function() {$(".testing").fadeOut
> ("slow");}, 500);
>        });
>    });
> </script>
>
>
> <div class="testing" style="display: none;">this is my dynamic created
> content </div>
>
> Thank you in advance.
>



-- 
Charlie Griefer
http://charlie.griefer.com/

I have failed as much as I have succeeded. But I love my life. I love my
wife. And I wish you my kind of success.

Reply via email to