jquery判断一个标签是否包含另外一个标签

jquery判断一个标签是否包含另外一个标签

一、总结

一句话总结:

jquery的find方法配合length属性:if($("#video_md_9_1").find("#video_comment_tabs_part").length==0)

二、jquery判断一个标签是否包含另外一个标签

  {{--当屏幕变小的时候:第一个col-md-9中的评论板块移动到第二个,先加第二个,再删第一个--}}
  <script>
      function fry_video_comment_part_move(){
          //console.log($(window).width());
          let video_comment_tabs_part=$('#video_comment_tabs_part');
          if($(window).width()>991){
              //如果位置是对的,就不用变,位置不对才需要变
              //如果#video_md_9_1没有#video_comment_tabs_part,就如下操作
              if($("#video_md_9_1").find("#video_comment_tabs_part").length==0){
                  $('#video_md_9_1').append(video_comment_tabs_part);
                  $('#video_md_9_2').remove('#video_comment_tabs_part');
              }

          } else{
              if($("#video_md_9_2").find("#video_comment_tabs_part").length==0){
                  $('#video_md_9_2').append(video_comment_tabs_part);
                  $('#video_md_9_1').remove('#video_comment_tabs_part');
              }
          }
      }
      $(function () {
          fry_video_comment_part_move();
          $(window).on('resize', function() {
              //console.log("宽度改变了!");
              //console.log($(window).width());
              //layer_alert_success($(window).width());
              fry_video_comment_part_move();
          }).resize();
          // window.onresize=function(){
          //
          // }
      });
  </script>

三、用jquery判断某个元素下是否有标签?

转自或参考:用jquery判断某个元素下是否有标签?
https://blog.csdn.net/linhui03/article/details/78682339

示例如下:

<script>

$(function(){

if($(".top-4").find("a").length==0){

$(".top-5").css("height","0px")

}

})

</script>

 
原文地址:https://www.cnblogs.com/Renyi-Fan/p/11927134.html