Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery hide/show div using variables

Tags:

jquery

I am a nOOb to jQuery.

I want to use variables in jQuery to hide/show divs.

what I have so far is:

$(document).ready(function(){
    $('#listMenu a').click(function () {
            var getPage = $(this).attr("id");
            var getName = $(this).attr("name");
            //console.log(getPage);
            //console.log(getName);

            $("#" & getName ).show();



    });
});

firebug console shows that I have the vars correctly, but I get this error next:

this[H].style is undefined [Break on this error] (function(){var R=/((?:((?:([^()]+)...typeof K==="string"?K:K+"px")}})})();

any help is appreciated. sjs

like image 585
ussteele Avatar asked Mar 17 '10 18:03

ussteele


2 Answers

i think you wanted to write

$("#" + getName ).show();

& is not an operator in javascript, but + is.

like image 199
mkoryak Avatar answered Sep 19 '22 16:09

mkoryak


use $("#" + getName ).show();

+ will concatenate strings.

like image 31
antpaw Avatar answered Sep 16 '22 16:09

antpaw