Wednesday 27 March 2019

How to hide a DIV when the user clicks outside of it

<script>
jQuery(document).on('click', function (e) {
    if (jQuery(e.target).closest(".sle1").length === 0 && jQuery(e.target).closest(".city-filter").length === 0) {
        jQuery(".city-filter").slideUp();
        jQuery(".sle1").removeClass("active");
    }
});
</script>

Saturday 23 March 2019

How do we apply jQuery for mobile only

 <script>
    $(document).ready(function () {
    $(window).on("resize", function (e) {
        checkScreenSize();
    });

    checkScreenSize();

    function checkScreenSize(){
        var newWindowWidth = $(window).width();
        if (newWindowWidth < 768) {
            jQuery(".recent-insight").insertAfter(".sidebar-right");
            $(".relateds .action-links ").insertBefore(".mob-block .vc_btn3-container");
        }else{
          $(".mob-block .action-links ").insertBefore(".relateds .vc_btn3-container");
        }
      
    }
});
  </script>