On Nov 10, 2009, at 7:58 AM, Michel Belleville wrote:
$(el).parents('div').get(0).addClass('myClass'); // should work, may be a testing error (just tested it, worked for me)
Interesting that this one worked for you. I wouldn't expect it to, since the .get() method is supposed to return a DOM element (when an index is passed in), and addClass should only operate on the jQuery object.

I would expect this to work:
$(el).parents('div').eq(0).addClass('myClass');
and this:
$(el).parents('div:eq(0)').addClass('myClass');
and this:
$(el).parents('div:first').addClass('myClass');
and, in 1.4 (sneak peek!), this:
$(el).parents('div').first().addClass('myClass');


--Karl

____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



Reply via email to