[Solved] html jquery click function not working? [closed]


Without seeing more of your code (both HTML and JavaScript), but it looks like you have a null reference exception in that you are creating the variable “loginoutbox”, but then attempting to reference the style property of a object called “cbox”.

You probably want to do this-

$("#hbox99").click(function(e) {
   var loginOutBox = document.getElementById("cbox"), fromTop = loginOutBox.style.bottom;

   if (fromTop === "0px") {
      $("#cbox").css('bottom',-365);
   }
   else {
      $("#cbox").css('bottom',0);
   }
});

As well as attempting to fix the code, I’ve assigned “fromTop” to a variable (otherwise it becomes an implicit variable), used camel case for the variable names to improve readability and used the (generally recommended) triple equals equality operator (which checks both type and value – a good habit to get into). I’ve also changed your “bottom” values from strings (surrounded by quotes) to integers, which if I remember correctly will be converted to pixels by jQuery for you.

If it is a fixed value rather than one which is calculated, then it may well be worth writing as a string but with the unit, e.g. ‘-365px’.

1

solved html jquery click function not working? [closed]