Correct Syntax for ui and nth-child call?
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 hav开发者_JAVA百科e:
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?
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.
精彩评论