views:

32

answers:

1

I'm still a bit new on jquery selection syntax (and jquery in general). I'm not exactly sure how to get this call to work.

I'm using a function that gives me an event and ui. I'm using the stop event in sortable and I'm trying to get the nth-child (first) from this element and then trying to clear it's class. right now I have:

 stop : function(event, ui) {
     $(ui.item):nth-child(1).removeAttr("class");
 }

But this gives me an unexpected ':' error. What's the correct syntax for this?

+2  A: 

Use .eq() here, or .first() (shortcut for .eq(0)), like this:

$(ui.item).eq(0).removeAttr("class");
//or:
$(ui.item).first().removeAttr("class");

The important difference to note here is that :nth-child() (used as a string selector) is 1-based, .eq() and :eq() (selector version) are 0-based.

Nick Craver
Thanks so much! This works great! My question was not exactly what I needed, but I figure out that I had to combine it with a .find(). Thanks!
Kevin