shachi
09-24-2006, 05:09 PM
Hello all again,
Can anyone tell me how do I check if any element has already been created(dynamically) and stop it from being generated again if it finds one instance of the object?? For e.g I have this code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Divs</title>
<style>
.rolloverdiv {
background-color: #F8F8F8;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #333333;
display: none;
padding: 4px;
border: 1px solid silver;
position: absolute;
left: 10px;
top: 10px;
}
</style>
<script>
function showtip(id, event, tip){
//var Div = document.getElementById(id);
var Div = document.createElement('div');
divId = new Object();
divId.id = Div;
divId.id.innerHTML = tip;
divId.id.style.display = 'block';
var x=event.clientX;
var y=event.clientY;
var Y = y+20;
divId.id.style.left = x+'px';
divId.id.style.top = Y+'px';
}
function hidetip()
{
divId.id.style.display = 'none';
}
</script>
</head>
<body>
<!--<div id="tip" class="rolloverdiv"></div>-->
<a href="" onMouseMove="showtip('tip', event, 'Hello, this is a text')" onMouseOut="hidetip()">This</a> is a text
</body>
</html>
It uses a div in the HTML initially but I need to change it so that the user(me) doesn't have to write that <div></div> in HTML again and again and it gets generated automatically. But each time the user hovers over the link it creates a new instance of the div how do I stop it from being created each time?? Do I simply create the object as soon as the window loads or what??
Thanks for reading this post. :)
Can anyone tell me how do I check if any element has already been created(dynamically) and stop it from being generated again if it finds one instance of the object?? For e.g I have this code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Divs</title>
<style>
.rolloverdiv {
background-color: #F8F8F8;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #333333;
display: none;
padding: 4px;
border: 1px solid silver;
position: absolute;
left: 10px;
top: 10px;
}
</style>
<script>
function showtip(id, event, tip){
//var Div = document.getElementById(id);
var Div = document.createElement('div');
divId = new Object();
divId.id = Div;
divId.id.innerHTML = tip;
divId.id.style.display = 'block';
var x=event.clientX;
var y=event.clientY;
var Y = y+20;
divId.id.style.left = x+'px';
divId.id.style.top = Y+'px';
}
function hidetip()
{
divId.id.style.display = 'none';
}
</script>
</head>
<body>
<!--<div id="tip" class="rolloverdiv"></div>-->
<a href="" onMouseMove="showtip('tip', event, 'Hello, this is a text')" onMouseOut="hidetip()">This</a> is a text
</body>
</html>
It uses a div in the HTML initially but I need to change it so that the user(me) doesn't have to write that <div></div> in HTML again and again and it gets generated automatically. But each time the user hovers over the link it creates a new instance of the div how do I stop it from being created each time?? Do I simply create the object as soon as the window loads or what??
Thanks for reading this post. :)