1

I have a situation where I need to loop through some values and then hide a div that has an id.

To simply here is a piece of code:

 var value = 'div1';
  $('#div1).hide();

what I like to do is to do something like:

 value.hide();

Meaning, pass what the value is and then hide it dynamically on document.ready().

4 Answers 4

4

Try like below,

  var value = 'div1';
  $('#' + value).hide();
Sign up to request clarification or add additional context in comments.

Comments

1

what I like to do is to do something like:

value.hide();

var value = $("#div1");
value.hide();

or

var value = 'div1';
$('[id="' + value + '"]').hide();​​​​​​​​​​​​

or what Vega said :)

Comments

0

You can use the variable like a string http://jsfiddle.net/

var value = 'div1';
$('#' + value).fadeOut(1000); ​

Comments

0

You could use something like the following:

var value = 'div#div1';
$(value).hide();

Comments

Your Answer

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.