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);
2 Answers 2
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>
1 Comment
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');