Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery Hide() and Show() Not Working -- Extremely Frustated

Tags:

jquery

hide

show

I have some HTML like this

<div id="topContainer">
 <div id="level1" style="display:none;"> </div>
 <div id="level2" style="display:none;"></div>
</div>

I can retrieve level1 and level2, calling show() and hide() on them successfully. However, having style="display:none;" and then calling jQuery("#topContainer").show() does nada. :(

What could possibly be wrong?

JS Below

//LOGIC HERE THAT SHOWS LEVEL1 and LEVEL2 based on business logic

//If neither div is shown (got a variable set to false, it set to true each time
//the business logic shows the div
//if variable is still false, then the below line runs
jQuery("#topContainer").hide()

Updated with as much code as I can.

like image 522
bobber205 Avatar asked Nov 30 '25 17:11

bobber205


1 Answers

.show() and.hide() on a parent doesn't affect the children, if they're hidden they stay hidden...they're handled independently.

However, you can call .show() on the children as well if needed, for example:

jQuery("#topContainer").show().children().show();
like image 72
Nick Craver Avatar answered Dec 03 '25 10:12

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!