ReferenceError: event is not defined. I'm facing problem with this

function toggle<?php echo $id; ?>(){
    var target = $(event.target);
    if(!target.is("a")){
    var element = document.getElementById("toggleComment<?php echo $id; ?>");
   if(element.style.display == "block"){
   element.style.display = "none";
  }else{
  element.style.display = "block";
   }
 }
}

I don’t see where event is being defined. The way you have this written, there is no event passed to the function. Is event being defined prior to the function?

V/r,

^ _ ^

Based on the usage of $(…), I would assume jquery, and that this function is being defined for the purposes of binding to a .click, in which case the problem is solved by putting the word event inside the parameter definition of the function.

However, assuming jquery, this can be simplified heavily as a generic function, using .toggle() and relative targetting.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.