[jQuery] Re: Question on filter()
Parent is the DOM node which contains the targeted element. So in your example td would be the parent of input. Label would be a sibling of input, or you could use the prev('label') method if you wanted to target the label element. -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of TimW66 Sent: Thursday, June 11, 2009 12:11 PM To: jQuery (English) Subject: [jQuery] Question on filter() Hi all, I have the following JS code: $('table.tableView :inp...@readonly]').parent().filter(function() { return !$('label', this).length; }).addClass('readonly'); -- And the following HTML code: table class=tableView thead tr thtest/th /tr /thead tbody tr td label for=fooFoo/label input id=foo type=text value=foo readonly=readonly/ /td /tr tr td input id=bar type=text value=bar readonly=readonly/ /td /tr tr td label for=zedFoo input id=zed type=text value=zed readonly=readonly/ /label /td /tr /tbody /table -- What I expected is the first and third input box to not get the readonly class. However, the third input box does get the readonly class. Isn't label a parent of input? I should also mention I'm using jQuery v1.2.6.
[jQuery] Re: Question on filter()
Never mind, figured out the issue. the return statement has a call that will look for label inside of the parent, not look at the parent itself. If I want to look at the parent, I'll have to use $(this).is ('label'). Sorry for the clutter! On Jun 11, 12:11 pm, TimW66 timwilso...@gmail.com wrote: Hi all, I have the following JS code: $('table.tableView :inp...@readonly]').parent().filter(function() { return !$('label', this).length; }).addClass('readonly'); -- And the following HTML code: table class=tableView thead tr thtest/th /tr /thead tbody tr td label for=fooFoo/label input id=foo type=text value=foo readonly=readonly/ /td /tr tr td input id=bar type=text value=bar readonly=readonly/ /td /tr tr td label for=zedFoo input id=zed type=text value=zed readonly=readonly/ /label /td /tr /tbody /table -- What I expected is the first and third input box to not get the readonly class. However, the third input box does get the readonly class. Isn't label a parent of input? I should also mention I'm using jQuery v1.2.6.