Target an area with Jquery
Hello everyone!
I've a button and this button opens a div. I've figured that when I target an area except this div it should be hide.
This is my codes but it doesn't work perfectly (actually it works slightly).
- <!--show hide div-->
- $(function(){
-
- $('.mybutton').click(function(){
-
- $('.mydiv')
- .show()
- });
-
- $('html').on('click', function(event){
-
- var target = $(event.target);
- console.log(target);
-
- if (target.is('.mydiv') || target.parents('.mydiv').size() > 0)
- return;
-
- $('.')
- .hide()
-
- });
- });
Anybody can fix that?