sam
sam

Reputation: 287

Unable to hide the div using jquery

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

Upvotes: 0

Views: 376

Answers (4)

Couldn't you actually do

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

and then just do

myDiv.hide();

Upvotes: 0

Shadow Wizard
Shadow Wizard

Reputation: 66389

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

Upvotes: 0

Mahesh KP
Mahesh KP

Reputation: 6446

Hope you are getting the correct id.

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

Upvotes: 0

Telémako
Telémako

Reputation: 673

You are missing the #

$('#'+id).whatever()

Upvotes: 1

Related Questions