Jquery选择器-每个选择器中的一个类

Jquery选择器-每个选择器中的一个类,jquery,class,this,selector,each,Jquery,Class,This,Selector,Each,我有一个名为guestline的类atribute的输入循环,我试图弄清楚输入字段是否已填充或未检查其类,但我一直使用选择器 $("div#acompanhantes div.acompanhante").each(function(i){ if($(this).next('.guestline').val() != '') { alert() } else {

我有一个名为guestline的类atribute的输入循环,我试图弄清楚输入字段是否已填充或未检查其类,但我一直使用选择器

      $("div#acompanhantes div.acompanhante").each(function(i){
            if($(this).next('.guestline').val() != '') {
                alert()
            }
            else {
                var fn = (vagasdispo > i ) ? 'show' : 'hide';
                $(this)[fn]();
            }


        });
Html是

     <div id='acompanhante_1' class='acompanhante'>
<h3>1o. acompanhante </h3>

<div class="form-group"><label for="Invited1Name" class="control-label col-md-3">Nome</label>

    <div class="col-md-8"><input name="data[Invited][1][name]" class="guestline guestline_1 form-control"
                                 maxlength="250" type="text" id="Invited1Name"/></div>
</div>
<div class="form-group"><label for="Invited1Phone1" class="control-label col-md-3">Telefone de Contato</label>

    <div class="col-md-8"><input name="data[Invited][1][phone_1]" class="validate[required] large form-control"
                                 type="text" id="Invited1Phone1"/></div>
</div>
<div class="form-group"><label for="Invited1Document1" class="control-label control-label col-md-3">Número do
    documento de identidade</label>

    <div class="col-md-8"><input name="data[Invited][1][document_1]" class="validate[required] large form-control"
                                 maxlength="255" type="text" id="Invited1Document1"/></div>
</div>
<div class=""><label class="checkbox inline"><input type="hidden" name="data[Invited][1][special_needs]"
                                                    id="Invited1SpecialNeeds_" value="0"/><input type="checkbox"
                                                                                                 name="data[Invited][1][special_needs]"
                                                                                                 colname="special_needs"
                                                                                                 value="1"
                                                                                                 id="Invited1SpecialNeeds"/>Portador
    de Necessidade Especial </label></div>

1o。公司
诺姆
康塔托电视台
努梅罗多
身份证明文件
Portador
特别必要

输入是
acompanhante
元素的后代,不是下一个同级元素,因此请使用而不是


使用
find
而不是
next

 if($(this).find('.guestline').val() != '') {

像这样的怎么样

var EmptyFields = $(".form-group :text[value='']");
if(EmptyFields.length > 0){
    alert('Please fill in all the text fields!');
    EmptyFields.addClass('error');
}else{
    $(".form-group .error").removeClass('error');
}

var EmptyFields = $(".form-group :text[value='']");
if(EmptyFields.length > 0){
    alert('Please fill in all the text fields!');
    EmptyFields.addClass('error');
}else{
    $(".form-group .error").removeClass('error');
}
$(".form-group :text").each(function(){
    if($(this).is("[value='']")){
        $(this).addClass('error');
        alert('this field is empty: '+$(this).attr('name'));
    }else{
        $(this).removeClass("error");

    }
});