jQuery:如何验证某个元素是否为空

【要求】:使用jQuery 如何验证某个元素是否为空

  ♪ 答:

<body>
    <div id="div1">aa</div>
    <input type="input" name="input1" value="bb">
    
    <div id="parent">
    <div></div>
    </div>
    
    <p class="pp">pp</p>
</body>

<script>
    /**
     * 判断是否有内容
     */
    // 方法1:
    var isDivEmpty = $('#div1').text() ? false : true;
    
    // 方法2:
    var isInputEmpty = $('input[name=input1]').val() ? false : true;
    
    /**
     * 判断是否有子元素
     */
    // 方法3:
    console.log( $('#parent').is(':empty') );
    console.log( $('#pp').is(':empty') );
</script>

原文地址:https://www.cnblogs.com/Ruth92/p/5879324.html