0

I am able to find the div name using the below code:

var id = $("textbox").closest("div").attr("id");

How can I hide the div based on above fetched id. I have tried with following code:

$(id).hide();

It doesn't seems to work

2
  • Is there a specific reason you're using the id and don't directly hide the div? $('textbox').closest('div').hide(); Commented Aug 2, 2012 at 8:02
  • what is textbox? if its id, you should use #textbox instead Commented Aug 2, 2012 at 8:10

4 Answers 4

1

You are missing the #

$('#'+id).whatever()
Sign up to request clarification or add additional context in comments.

Comments

0

Hope you are getting the correct id.

Then use $('#'+id).hide();

Comments

0

You don't need the ID in the first place, just use the jQuery object you already got:

$("textbox").closest("div").hide();

If you want the ID for later use then store the object locally:

var oClosest = $("textbox").closest("div");
oClosest.hide();
var id = oClosest.attr("id");

Comments

0

Couldn't you actually do

var myDiv = $("textarea").closest("div");

and then just do

myDiv.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.