<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
//function del () {
var x= new Date ();
var date= x.getDate ();
var hours= x.getHours();
var minutes=x.getMinutes();
var sec= x.getSeconds();
document.write(minutes +":"+ sec )
if (minutes=="33"){
//alert ("time is over")
document.getElementById('airtel').removeChild(airtel);
}
//}
</script>
</head>
<body>
<div id="airtel">
<div id="vodafone">vodaphone</div>
<div id="idea">idea</div>
</div>
</body>
</html>
-
Try to explain what you tried and what went wrong.Bas Slagter– Bas Slagter2011-09-05 12:08:13 +00:00Commented Sep 5, 2011 at 12:08
Add a comment
|
3 Answers
Using jQuery Library removes the pain from using Javascript for handling the DOM, i sugest you give it a try.
But if you just want that working in native Javascript, what you need to do is traverse to the parentNode and then remove the child you want.
var element = document.getElementById('airtel');
element.parentNode.removeChild(element);
3 Comments
Jürgen Strobel
This should work, please tell us of errors. Seeing your date code, I suspect something really different is not working. You only check if minutes==33 when the document is loaded. You need to set up a timer and do that when minutes reach 33 or some other time.
svrx
According to the tests i made this works fine, but tell me your what's your browser and if you got any Javascript exceptions and i'll check it later.