Reputation: 287
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
Reputation: 5681
Couldn't you actually do
var myDiv = $("textarea").closest("div");
and then just do
myDiv.hide();
Upvotes: 0
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