1
<!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>
1
  • Try to explain what you tried and what went wrong. Commented Sep 5, 2011 at 12:08

3 Answers 3

8

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);
Sign up to request clarification or add additional context in comments.

3 Comments

i tried this but it is not working, could be please give me more suggestions
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.
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.
2

Maybe you are better off using jQuery with it's remove method for this.

Comments

0

You should get the element of 'airtel' then remove it from it's parent, which is the Body tag.

var airtel= document.getElementById('airtel');    
document.getElementsByTagName('body')[0].removeChild(airtel);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.