This question already has an answer here:
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 ';'
</div>
echo '<div onclick="$(\'.mob-top-menu\').slideToggle(\'fast\');" class="mob-menu-button"></div>';
Try this one,
echo '<div onclick="$(".mob-top-menu").slideToggle("fast");" class="mob-menu-button"></div>';
?>