简体   繁体   English

当JSON为空时,jQuery removeClass无法删除

[英]jQuery removeClass failed to remove when JSON is empty

I have this HTML structure : 我有这个HTML结构:

<div class="row">
    <div class="col-sm-6 p-l-0">
      <div class="form-group form-group-default form-group-default-select2 required">
        <select class="kurir">
        <option select="selected"></option>
        ...
        </select>
      </div>
    </div>
    <div class="col-sm-6">
      <div class="form-group form-group-default form-group-default-select2 required">
        <select id="tarif" class="tarif full-width">
        ...
        </select>
      </div>
    </div>
    <div class="col-sm-12 notarif">
        <p class="small hint-text no-margin text-danger hidden">
            some text here.
        </p>
    </div>
</div>

and I have this javascript : 我有这个javascript:

$(".kurir").change(function() {
    var _thiscache = $(this);
    $.ajax({
        url: json_url,
        dataType: "JSON",
        success: function(json){

            if ( json.length == 0 ) {
                $(".tarif").prop("disabled", true);
                $(".tarif").select2("val", "");
                _thiscache.closest(".row").find(".notarif").$("p").removeClass("hidden");
            }

        }
    ...

why I can't remove hidden class on p when JSON gives me empty result? 当JSON给我空结果时,为什么我不能删除p上的hidden类? what did I missed here? 我错过了什么? thank you for your attention. 感谢您的关注。

Instead of 代替

_thiscache.closest(".row").find(".notarif").$("p").removeClass("hidden"); //wrong selector and syntax

Use 采用

_thiscache.closest(".row").find(".notarif p.hidden").removeClass("hidden");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM