jquery select inputs that do not have a parent with a particular class

javascript, jquery

Solution

if your inputs are all contained with div's;

if you want top level to bottom level parent check:

$("div:not(.not-parent) input").css('color', '#FF1200');

or if you want only one level parent check:

$("div:not(.not-parent) > input").css('color', '#FF1200');

Edit: if it has ancestors of the same type without the class use this:

$('input').filter(function(){
    return !$(this).parents('div').hasClass('not-parent');
}).css('color', '#FF1200');

Problem

How can I select all inputs that do not have an parent of a particular class? Here I just want to get the inputs that do not have a parent with the class `not-parent` ``` $(document).ready(function(){ $('input:text').css('color', '#FF1200'); });​ ``` http://jsfiddle.net/MFtv3/ I have tried `filter()` without success. :/ Thanks!

Original source