-2

My callback function is not working. What am I doing wrong?

<script>
 $("button").click(fnction(){
  $("p").hide("slow", function(){
    alert("The paragraph is now hidden");
  });
 });
</script>
Phil
  • 157,677
  • 23
  • 242
  • 245

2 Answers2

1

the word function is misspelled

$("button").click(fnction(){

Fix it.

$("button").click(function(){
Tigran Abrahamyan
  • 756
  • 1
  • 4
  • 7
0

You have a typo. Use arrow functions for callbacks.

<script>
 $("button").click(() => {
  $("p").hide("slow", () => {
    alert("The paragraph is now hidden");
  });
 });
</script>
Charlie
  • 22,886
  • 11
  • 59
  • 90
  • Using arrow functions with jQuery comes with its own set of pitfalls. Not really recommended – Phil Oct 29 '20 at 07:35
  • Thanks. Can you give me a reference? – Charlie Oct 29 '20 at 14:33
  • [Using jQuery $(this) with ES6 Arrow Functions (lexical this binding)](https://stackoverflow.com/questions/27670401/using-jquery-this-with-es6-arrow-functions-lexical-this-binding) – Phil Oct 29 '20 at 23:27
  • Thanks. However the 'this' keyword is not used in this particular solution. – Charlie Oct 30 '20 at 07:23