2

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?

2
  • 1
    Post a complete code sample with a tiny bit of your HTML and the javascript in it. Because this should work and so it's likely you have something else going on.
    – Alex Wayne
    Commented Feb 13, 2010 at 19:43
  • I assume you're not missing the end ')' in your code. Otherwise it wouldn't work in the other browsers. Other than that, Safari will have no trouble with this code. Probably a mistake elsewhere is affecting it.
    – user113716
    Commented Feb 13, 2010 at 19:47

4 Answers 4

3

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. . .

1
  • 2
    Did you find an answer to this? I'm having the same issue. Commented Dec 5, 2010 at 21:33
1

Have you tried this?

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

Note the extra ; and );

0

Put a semicolon after hide().

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

0

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();
});
1
  • The "return false;" keeps the event from bubbling up to higher level objects. Commented Feb 13, 2010 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.