jquery - Selector doesn't work -


i've got problem form validation: have 2 div-container each 2 answers. validate wheter there minimum checked 1 radio or there value in 1 text element.

but jquery selector doesn't work:

html:

<div class="mandatory">     <input type="radio" value="1" name="answer1" /> option 1     <input type="radio" value="2" name="answer1" /> option 2 </div>  <div class="mandatory">     <input type="radio" value="1" name="answer2" /> option 1     <input type="text" name="answer2" /> </div> 

js:

$('.mandatory').each(function(){     var elem = $(this).find('input:checked, input:text[value!=""]');     console.log(elem.attr('name')); //always "answer2" }); 

it returned input element although empty. here code: http://fiddle.jshell.net/pisi2012/n9s2y/

thanks help!

your input doesn't have value attribute, attributes selector matches, value isn't empy string, there no value ?

change

<input type="text" name="answer2" /> 

to

<input type="text" name="answer2" value="" /> 

fiddle


Comments