Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable click functionality of div in javascript or jquery?

I disabled the div by using following code

$("#menuDiv1").children().bind('click', function(){ 
     return false; 
});

menuDiv contains

<ul>
    <li><a class="home" href="#/Dashboard">Dashboard</a></li>
    <li><a class="forms" href="#/ViewLeads">Lead</a></li>
    <li><a class="forms"  href="#/ViewCases/0">Cases</a></li> 


</ul>

but now I want to enable it again. How can I do that?

And is there any other solution for the same in angular js?

like image 934
Sunil Garg Avatar asked Jun 03 '15 06:06

Sunil Garg


1 Answers

you can use unbind to remove disable click event

 $("#menuDiv1").children().unbind('click');

To re enable click event use below code.

  function clickfunc(){
     // your code
  }

  $("#menuDiv1").children().bind('click',clickfunc); 

Second option

you can use off to remove disable click event

$("#menuDiv1").children().off('click');

To re enable click event use below code.

  function clickfunc(){
     // your code
  }

  $("#menuDiv1").children().on('click',clickfunc); 

EDIT as discussed below code is avoid click event on a,button tags.

DEMO

function clickfunc(event){
     if(event.target.nodeName === 'A' || event.target.nodeName == "BUTTON"){
      return false;
     }

      // your code
     alert("click")
}

$("#menuDiv1").children().on('click',clickfunc); 
like image 91
Nishit Maheta Avatar answered Oct 03 '22 06:10

Nishit Maheta