I am trying to use jQuery to find text areas that do not have a sibling of a certain class. Currently I am using the following:
$("textarea").not($("textarea").siblings(".siblingClass").siblings("textarea"))
Is there an alternative?
Sorry for the lack of context. The problem I am having is that I have a jquery plugin (maxlength) that runs multiple times (due to dynamic changes) and adds a div after textareas. The plugin does not check if it has already been run, so it will add the div multiple times.
If I understand the question correctly, .filter() can be useful.
$('textarea').filter(function(){
return $(this).siblings('.that-class').length == 0;
});
$('textarea').filter(function(){
return $(this).siblings('.a').length == 0;
}).css( "color", "red" );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<div>
<div class="a"></div>
<textarea>one</textarea>
<div class="b"></div>
</div>
<div>
<div class="c"></div>
<textarea>two</textarea>
<div class="c"></div>
</div>
<div>
<textarea>three</textarea>
</div>
<div>
<div class="a"></div>
<textarea>four</textarea>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With