Reputation: 77
I want to create a <div>
(display: none) then when I click on the button, the <div>
should show itself.
But I get this error:
Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$'
when I use this code:
$('body').click(function () {
$('#editor_form').hide();
});
$('#buttonDiv').click(function (e) {
$('#editor_form').sho`enter code here`w();
e.stopPropagation();
});
Upvotes: 0
Views: 95
Reputation: 3398
You just don't close <?php
and start adding some javascript inside php.
<?php
...
$('body').click(function () {
$('#editor_form').hide();
})
Just close <?php
with ?>
before adding js to solve the problem.
Upvotes: 0
Reputation: 86
The Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$'
is commonly a PHP syntax error, yet you are referring to jQuery code.
As you haven't given much more information on the environment or where you are writing your code, you will have to move your jQuery into a JavaScript file (recommended) and include it in your HTML Head or escape the code to stop the php parser from reading it.
Refer to this tutorial for more information on including external JavaScript files: http://javascript.info/tutorial/adding-script-html
Upvotes: 0
Reputation: 7203
The error you got is a PHP one but you are writing Javascript (with jQuery).
Your Javascript code need to be placed inside <script></script>
tag on a HTML file or directly on a js file included in your HTML file.
Maybe if you have HTML and PHP on same file, you forgot a PHP closing tag ?>
before starting to write your JS code.
Moreover, be careful, you have a placeholder that will also cause an error on this line :
$('#editor_form').sho`enter code here`w();
Upvotes: 2