Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery select all form fields except other fields

Tags:

jquery

<form id="test">
   <input type="text" name="title" value="I am title">
   <div id="text1">
      <input type="text" name="module-title" value="I am module title">
   </div>
   <div id="test2">
      <input type="text" name="article-title" value="I am article title">
   </div>
</form>

How do I select by jquery all the form (i.e. #test) input fields, except all the input fields which are inside "#test2".

like image 896
raian Avatar asked Dec 15 '22 06:12

raian


2 Answers

Try

$('#test input:text').not('#test2 input:text')
like image 108
Arun P Johny Avatar answered Jan 13 '23 00:01

Arun P Johny


$('#test :input:not(#test2 :input)')

:input is a special pseudo-selector which matches all input elements, like input, select and textarea.

JSFiddle: http://jsfiddle.net/vudS3/

like image 36
Andreas Eriksson Avatar answered Jan 12 '23 23:01

Andreas Eriksson