0

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();
});
2

3 Answers 3

2

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();
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.