By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,569 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,569 IT Pros & Developers. It's quick & easy.

Dynamic use of <DIV>'s

P: 25
Hi,
I'm using PHP to echo or stream out some DIV tags with content inside, by a user selection, and after a page has initially loaded.

My question is, Can I erase this dynamically created DIV container through a "close" button within the DIV... or... some other method?

thank you.
Sep 8 '06 #1
Share this Question
Share on Google+
4 Replies


Banfa
Expert Mod 5K+
P: 8,916
you can't erase it but you can hide it by setting it's display style to none in javascript, this could be called from a button or link

[html]
<script type="text/javascript">
<!--

function HideElement( id )
{
var el = document.getElementById(id);

if (el)
{
el.style.display = "none";
}
}

//-->
</script>
[/html]
Sep 8 '06 #2

P: 25
thanks for that info, which leads me to anther question.
If I hide the DIV and keep on dynamically creating a new ones, will I potentially run into memory or resource problems.

Perhaps if I use the same name or id for the DIV, then would that effectively destroy any previous instance of the DIV?

Is that logic correct?

thx
Sep 10 '06 #3

drhowarddrfine
Expert 5K+
P: 7,435
You cannot use the same id for a div on the same page. Use class instead.
I do not see how any of this would cause memory problems.
Sep 10 '06 #4

Banfa
Expert Mod 5K+
P: 8,916
thanks for that info, which leads me to anther question.
If I hide the DIV and keep on dynamically creating a new ones, will I potentially run into memory or resource problems.

Perhaps if I use the same name or id for the DIV, then would that effectively destroy any previous instance of the DIV?

Is that logic correct?
No.

As already said you can only use an ID once on a page. However you can re-write the contents of a div so you could re-use the one you already have.

[html]
<script type="text/javascript">
<!--
function WriteElementText( id, text )
{
var el = document.getElementById(id);

if (el)
{
el.innerHTML = text;
}
}
//-->
</script>
[/html]

If you keep on creating divs then ultimately you will get an out of memory error.
Sep 11 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.