tags:

views:

16975

answers:

3

Hi there,

I can't figure it out how to get an element of a clicked list item. When I use this I get "node-205" every time.

.find('> ul')
.tabs({
 selectedClass: 'active',
 select: function(event, ui){ 
 $(this).children('li').attr('class')) // this shows only the first element of the list
 } ,
 cookie: { expires: 0},
 fx: fx
 })

the list:

<ul class="tabs">
    <li class="node-205"></li>
    <li class="node-150"></li>
    <li class="node-160"></li>
</ul>

I hope someone can help me.

+4  A: 

This should do the trick:

...
select: function(event, ui){ 
   ui.tab.attr('class');
} ,
...

For more info about the ui.tab see http://jqueryui.com/demos/tabs/#Events

ToRrEs
What does this mean? Could you explain that more?
It's ui.tab instead of ui.item you need to use. I thought it was ui.item.
ToRrEs
+7  A: 

Here's a quick jQuery example that adds a click event to each "li" tag, and then retrieves the class attribute for the clicked element. Hope it helps.

$("li").click(function() {
   var myClass = $(this).attr("class");
   alert(myClass);
});
Sohnee
I'm sorry I don't know where to put this.. I need some more hints..
Pop it inside a script block just before the </body> tag. - Your script tag is <script type="text/javascript">
Sohnee
"class" is not a valid variable name.
Fred Bergman
A: 

check out the .each() method http://api.jquery.com/each/

Roman