-
Jan 26th, 2021, 01:47 PM
#1
Thread Starter
New Member
Hide a DIV when page renders
I'm trying to do some minor changes on a web application but the source code is missing. I think I can modify the ASPX page for minor visual changes and that's what I'm trying to do but not really adept to HMTL scripting.
Page has several buttons. When a button is pressed, a DIV with labels inside is displayed. One button incorrectly shows 2 DIVs. I want to hide one
when page renders. I cannot use the OnClick to call a function because it is already used in Code Behind.
How can I hide/intercept page render for one of the DIV when both DIVs are visible?
TIA
-
Jan 26th, 2021, 02:07 PM
#2
Thread Starter
New Member
Re: Hide a DIV when page renders
It looks like I can use this script below. It hides DIV2 but I want to use it only when DIV1 and DIV2 is visible on the screen. How do I check for that condition?
<script>
window.onload = function(){
document.getElementById("myDIV2").style.display='none';
};
</script>
-
Jan 26th, 2021, 02:53 PM
#3
Re: Hide a DIV when page renders
Set the style of the one div to hidden right from the start... you're over thinking it. You don't need to do it from script... just set it's style to hidden right from the start.
Then when you want to show it, remove the hidden style. It's as simple as that.
-tg
-
Jan 26th, 2021, 02:55 PM
#4
Thread Starter
New Member
Re: Hide a DIV when page renders
Looks like this worked when I tested. I'm open to other inputs.
Code:
<script>
window.onload = function(){
var x = document.getElementById("myDIV1");
var y = document.getElementById("myDIV2");
if ((x.visibility !== "hidden") && (y.visibility !== "hidden")){
document.getElementById("myDIV1").style.display='none'};
};
</script>
Last edited by LUCKY_PRINCE; Jan 26th, 2021 at 03:07 PM.
-
Jan 26th, 2021, 03:04 PM
#5
Thread Starter
New Member
Re: Hide a DIV when page renders
Originally Posted by techgnome
Set the style of the one div to hidden right from the start... you're over thinking it. You don't need to do it from script... just set it's style to hidden right from the start.
Then when you want to show it, remove the hidden style. It's as simple as that.
-tg
Yeah all DIVs hidden from the start.
click BUTTON 1 displays DIV1 and hides all other DIVs
click BUTTON 2 displays DIV2 with DIV1 (DIV1 should not be showing)
click BUTTON 3 displays DIV3 and hides all other DIVs
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|