jquery - My first function is having a syntax error -
hello getting writing functions , think bit on head. javascript console stating
uncaught error: syntax error, unrecognized expression: "#insert jsfiddle url"
since don't have enough reputation cannot post 2 links, "insert jsfiddle url" jsfiddles url, becomes url of site run code on.
here code code it:
function menuclick(menuitem, menucontent) { $('"#' + menuitem + '"').click(function() { $('#cssmenu').hide(); $('"#' + menucontent + '"').show(); $('#goback').show(); }) }; menuclick(aboutlink, aboutcontainer);
in code $('"#' + menuitem + '"') wrong.
when menuitem = "hello", above code becomes $('"#hello"') not want.
you want $('#' + menuitem) results in $('#hello') when menuitem = "hello"
check out fiddle.
here 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>
Comments
Post a Comment