Pradip Shenolkar
asked on
How to reuse div tag to display different information everytime in javascript?
html code:
js code:
I am calling this function on onclick listener. But everytime when I call this js function, new div tag is added to page.
The problem : I want to hide earlier div and display only new div.
How to resolve this ?
<html>
<body>
<div id="container">
</body>
</html>
js code:
function call_me()
{
container=document.getElementById('container');
//do something
}
I am calling this function on onclick listener. But everytime when I call this js function, new div tag is added to page.
The problem : I want to hide earlier div and display only new div.
How to resolve this ?
You can't create new div with the same id ("container") as the existing one. If you still want to keep the old data hidden when new data is coming, then you'd better put data into child div of your "container" div, and hide old child divs when data is coming. E.g:
$('#container > div[class="child-div"]').hide();
$('#container').append('<div class="child-div">Your data in HTML here</div>");
Hi,
@Duy Pham: sorry, but there is no jQuery topic assigned nor any jQuery usage mentioned - therefore a good plain Javascript question and it might complicate things to introduce jQuery into this question and even if your code sample could solve the issue, it is not on the right track.
KR
Rainer
@Duy Pham: sorry, but there is no jQuery topic assigned nor any jQuery usage mentioned - therefore a good plain Javascript question and it might complicate things to introduce jQuery into this question and even if your code sample could solve the issue, it is not on the right track.
KR
Rainer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks alot.
Open in new window
After this, I don't see what you're adding a new div anywhere in your code.Is this all you are executing?