views:

43

answers:

2

i want to show a tooltip when i highlight over any text inside of "class=div". I have the following HTML:

<div class='test'>Test</div>
<div class='tooltip'>Tooltip 1</div>

<div class='test'>Test 2</div>
<div class='tooltip'>Tooltip 2</div>

<div class='test'>Test 4</div>
<div class='tooltip'>Tooltip 4</div>

and the following javascript:

<script type="text/javascript">
        $(document).ready(function () {

            $('div.test').each(function () {

                var tooltipHtml = //NEED to figure out how get the html of the Tooltip div below this current div
                $(this).qtip({
                    content: {
                        text: tooltipHtml
                    },
                    style: { width: 450 }
                });
            });
        });

How do i get the html from the "next" tooltip div?

+5  A: 

1: Use jQuery next() to select it.

var tooltipHtml = $(this).next('.tooltip').html();
Blair McMillan
@Blair McMillan - i seperated the questions into two different questions
ooo
Ok, I'll remove that part then.
Blair McMillan
A: 

If all you want is a tooltip why not do it like this:

<div class="test" title="Tooltip 1">Test 1</div>
<div class="test" title="Tooltip 2">Test 2</div>
<div class="test" title="Tooltip 4">Test 4</div>

<script>
$('.test[title]').qtip({ style: { name: 'cream', tip: true } })
</script>

qTip automatically uses the title attribute if no content is set.

JKirchartz