or you could use a delegate/live (if you aren´t using jquery 1.7+), if you want all your #closebox a elements that exists on the page now or in the future (with jquery and ofcouse then you cant have and id of #closebox) then you could use:

load() uses ajax, which is asynchronous so it loads in the background while your script keeps going. This means that when you are trying to access #closebox on the next line in your script, it does'nt yet exist as it has'nt been inserted into the DOM yet. You'll have to wait until the load() function is completed, and luckily load() has a callback function for this. Also, whenever you use return, the script ends and returns, so you'll have to do:

They both do the same thing, but I get your point - that using event.preventDefault() is better than return false; since it can occur anywhere in the callback, and is more explicit in what it does.
–
GregLAug 23 '12 at 5:40

return false also stops propagation in jQuery, otherwise it's the same thing. I usually use preventDefault unless I intend to also stop propagation.
–
adeneoAug 23 '12 at 5:44

hi everyone . i tried the code above but the .removeClass did not work. i tested the code. i.e i used an alert to see if the last click work, adn the alert worked. so, the problem is with the remove class. it is not removing the element.
–
andreea115Aug 23 '12 at 11:43

You need to delegate the function to a static parent element that exists on page load. We refer to this as 'Bubbling' or 'Event Propagation'. in jQuery's latest version, we use the .on() function to perform these actions.

The return false is within the click handler. Her code needs two }).
–
VohumanAug 23 '12 at 5:34

@undefined - yes, but there is two of them?
–
adeneoAug 23 '12 at 5:36

@adeneo One for the first click handler and another one for ready.
–
VohumanAug 23 '12 at 5:38

@undefined - ready is'nt closed, the first is for the first click handler, and the second is for the second click handler, but it never gets there as it returns before the second click handler (it's inside the first).
–
adeneoAug 23 '12 at 5:42

@adeneo Correct, ready hasn't been closed, I think she just has forgotten to close/post the first and last}).
–
VohumanAug 23 '12 at 5:45