Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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
$('textbox').closest('div').hide();
You are missing the #
$('#'+id).whatever()
Add a comment
Hope you are getting the correct id.
Then use $('#'+id).hide();
$('#'+id).hide();
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");
Couldn't you actually do
var myDiv = $("textarea").closest("div");
and then just do
myDiv.hide();
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
$('textbox').closest('div').hide();