html - jQuery with complex selector -


i have list of input control in application. want find input control, have written following js code working fine.

html

<input id="txt1" value="sdgjhsgd" type="text" /> <div class="tab active">     <input id="txt2" value="gf5" type="text" />     <input id="txt3" value="4r" type="text" />     <input id="txt4" value="345" type="text" /> </div> <div class="tab">     <input id="txt21" value="dfg" type="text" />     <input id="txt31" value="56" type="text" />     <input id="txt41" value="67" type="text" /> </div> <div class="tab">     <input id="txt22" value="df" type="text" />     <input id="txt32" value="32" type="text" />     <input id="txt42" value="65" type="text" /> </div> 

js

var inputs = $(":input:not(input[type='hidden'])"); 

fiddle

now want find input controls parent div has class name active , input controls without parent. have used following code failed.

var inputs = $(":input:parent('div')[classname='tab active']:not(input[type='hidden'])"); 

so input has selected is

txt1 txt2 txt3 txt4 

for selecting inputs inside div parent class 'active' use this:

$(".active input:not([type='hidden']"); 

for selecting input controls without parent use following:

$(".your-container > input:not([type='hidden'])"); 

the element class "your-container" should wrapper element of posted html code.

together can use following (not recommended, it's long selector):

 $(".active input:not([type='hidden'], .your-container > input:not([type='hidden'])"); 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -