views:

265

answers:

4

I have jQuery .click(function() event handlers attached to elements that I've selected by ID

example:

$('#deletethis').click(function() {
   $(this).hide()
} 

within my $(document).ready but this does not work at all with Safari, just nothing happens but it works fine with Chrome, Firefox, and IE. Console reports no javascript errors. Nothing inside the .click handler gets executed at all. Is there a work around for safari to accomplish the same effect?

A: 

Have you tried this?

$('#deletethis').click(function() { $(this).hide(); });

Note the extra ; and );

philwilks
A: 

Put a semicolon after hide().

End the click function with a ');' after the function.

Robert
A: 

Is #deletethis a link? Possibly with href="". If so, the default action on it is to navigate to the url of the page.

You can prevent the default action by calling e.preventDefault() in the click handler.

$('#deletethis').click(function(e) {
    e.preventDefault();
    $(this).hide();
});
Lachlan Roche
The "return false;" keeps the event from bubbling up to higher level objects.
Robert
A: 

Nevermind, found out it was an issue with only Safari not loading the javascript file, but all other browsers are. Got to figure that out now. . .

Joren