0

I want to hide a container div with jQuery, I tried to add some code but doesn't work, anyone tell me how to solve this ?

The url is: http://35.201.250.64 In the mobi version, I want to click class .tatx , the id #sidr hide, I use the code bellow:

$(document).ready(function() {
        $(".tatx").click(function() {
            $("#sidr").css("display", "none!important");
                       //$("sidr").css("display", "none");
                       //$("#sidr").hide();
        });
    });

and I also want to click outside, the id sidr hide too, I tried this code:

$(document).mouseup(function(e){
    var container = $("#sidr");
    if(!container.is(e.target) && container.has(e.target).length === 0){
      container.hide(500);
    }
  });
Liu Chang
  • 3
  • 1
  • Try to separate de "none !important". Check the element is present in the page when the page loads. This means, that isn't brought dynamically. – MarkSkayff Jun 10 '19 at 02:30
  • @MarkSkayff Actually, jQuery `.css()` is not compatible with `!important` at all, regardless of syntax. That said, there are [workarounds](https://stackoverflow.com/questions/2655925/how-to-apply-important-using-css). – Tyler Roper Jun 10 '19 at 02:35
  • I use console and test $(".tatx") but it's length is 0. – BeiBei ZHU Jun 10 '19 at 03:08

1 Answers1

0

How about this

$(document).ready(function() {
   $(".tatx").on('click', function() {
      $("#sidr").toggle();
   });
});

or

$(document).ready(function() {
   $(this).on('click', '.tatx', function() {
      $('#sidr').toggle();
   });
});
Joppx
  • 82
  • 8
  • Thanks for your help, But it's still doesn't work! :) – Liu Chang Jun 10 '19 at 02:36
  • @LiuChang Can you paste your codes in codepen so that we can have a better understanding of your code. :) – Joppx Jun 10 '19 at 02:40
  • I use wordpress, and install plugin eDS Responsive Menu , so that I can't paste it to codepen, you can view code at http://35.201.250.64/ ( in mobi version ), I want to hide "#sidr" when click ".tatx". – Liu Chang Jun 10 '19 at 02:44