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); 

here link jsfiddle of it.

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

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -