-1

please can someone help me correct the error below. I am trying to echo div tag with onclick attribute from a JavaScript file. please how can i correct this am just a beginner, thanks

<?php 
    echo '<div onclick="$('.mob-top-menu').slideToggle('fast');" class="mob-menu-button"></div>';
?>

this is the error I got when I ran the code

Parse error: syntax error, unexpected '').slideToggle('' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'

u_mulder
  • 54,101
  • 5
  • 48
  • 64
bright_w
  • 1
  • 4

2 Answers2

1
echo '<div onclick="$(\'.mob-top-menu\').slideToggle(\'fast\');" class="mob-menu-button"></div>';
toor
  • 101
  • 5
0

Try this one,

echo '<div onclick="$(".mob-top-menu").slideToggle("fast");" class="mob-menu-button"></div>';
 ?>
Siva
  • 1,481
  • 1
  • 18
  • 29