1

Hello I am just getting into writing functions and I think I am a bit over my head. The javascript console is stating

Uncaught Error: Syntax error, unrecognized expression: "#insert the jsfiddle url"

Since I don't have enough reputation I cannot post two links, but where "insert the jsfiddle url" is the jsfiddles url, it becomes the url of any site I run this code on.

Here is the code is the code for it:

 function menuclick(menuitem, menucontent) {
 $('"#' + menuitem + '"').click(function() {
 $('#cssmenu').hide();
 $('"#' + menucontent + '"').show();
 $('#goback').show();
 })
};
 menuclick(aboutlink, aboutcontainer);

Here is the link to a jsfiddle of it.

asked Aug 3, 2015 at 7:48

2 Answers 2

1

In your code $('"#' + menuitem + '"') is wrong.

When menuitem = "hello", the above code becomes $('"#hello"') which is NOT what you want.

You want $('#' + menuitem) which results in $('#hello') when menuitem = "hello"

Check out this fiddle.

Here is the snippet.

$('#aboutcontainer').hide();
$('#goback').hide();
function menuclick(menuitem, menucontent) {
 $('#' + menuitem).click(function() {
 $('#cssmenu').hide();
 $('#' + menucontent).show();
 $('#goback').show();
 })
};
menuclick('aboutlink', 'aboutcontainer');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="cssmenu"><a href="#" id="aboutlink">About</a>
</div>
<div id="aboutcontainer">djdsidjkjd
 <br>
 <br>
</div>
<div id="goback">Go back</div>

Dietz
5785 silver badges14 bronze badges
answered Aug 3, 2015 at 7:54
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much that makes sense.
1

You have a lot of errors and problems. Here you are your fiddle working:

http://jsfiddle.net/gqwugdf3/2/

What I do:

Remove unnecesary double quotes :

 $('"#' + menuitem + '"') //incorrect
 $('#' + menuitem) // correct

put quotes in calling

 menuclick('aboutlink', 'aboutcontainer');
answered Aug 3, 2015 at 7:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.