Jump to content

[SOLVED] show/hide div issue


matfish

Recommended Posts

Hi, my javascript skills are not as good as my php but ill address the issue.

 

Iv got a simple show/hide div (display:none; display:block; kinda thing). Onload its shown, and the content within is displayed. but then i hide it, but when i click the link to display it again the content within is gone? But this is only happening in IE, FF works no probs.

 

Any ideas why is does this?

 

JS:

function show_images(){
document.getElementById('img_list').style.display='block';
}
function hide_images(){
document.getElementById("img_list").style.display="none";
}

Link to comment
Share on other sites

I normally like it all in one function. Like this...

 

function showHideDiv(id) {
   div = document.getElementById(id);
   div.style.display = (div.style.display == 'none')? 'block' : 'none';
}

 

Try that and I bet you will find it easier to work with.

Link to comment
Share on other sites

Hi, the code you provided is just a neater way of what I did - thanks - but I still get the issue of the contents within the DIV are not displayed when I toggle the show/hide link.

 

I do have 3/4 div's within this 1 div Im toggling  - would this cause an issue?

 

Thanks for your replies.

Link to comment
Share on other sites

The div im trying to show/hide is the id="img_list"

 

<div class="top_right_image_space" id="img_list">
<div id="motioncontainer">
	<div id="motiongallery">
		<nobr id="trueContainer">
			<a href="javascript:void(0);" onclick="javascript:change_image('1');">
			<img src="image_assets/thumb_image1.jpg" border="1" alt="1"></a>
			<a href="javascript:void(0);" onclick="javascript:change_image('2');">
			<img src="image_assets/thumb_image2.jpg" border="1" alt="2"></a>
		</nobr>
	</div>
</div>
	<div class="hide_more_images">
		<a href="javascript:void(0);" onclick="javascript:hide_images();" class="hide_link">[X]</a>
	</div>
</div>

 

But when its shown again the contents within has disappeared. This only happening in IE.

 

Many thanks

Link to comment
Share on other sites

Hi, thanks for the replies.

 

I did a bodge job and rather than hiding/showing the div, I resized it to show/hide and this works. Like this:

 

function show_images(){
//document.getElementById('img_list').style.display='block';
document.getElementById('img_list').style.height='130px';
document.getElementById('motioncontainer').style.height='95px';
document.getElementById('motiongallery').style.height='95px';
document.getElementById('hide_more_images').style.display='block';
document.getElementById('img_desc').style.display='block';
}
function hide_images(){
//document.getElementById("img_list").style.display='none';
document.getElementById('img_list').style.height='0px';
document.getElementById('motioncontainer').style.height='0px';
document.getElementById('motiongallery').style.height='0px';
document.getElementById('hide_more_images').style.display='none';
document.getElementById('img_desc').style.display='none';
}

 

Iv got another JS issue but ill post when ready in appropriate section.

 

Thanks again.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.