This should not be a difficult task, but for any reasons it keeps not working and I am not able to figure out why. Basically, I want to remove the paragraph with the class name "def" in the code below, but the getElementsByClassName method used in the script section seems unable to detect it, returning no elements:
<!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>
<script language="javascript">
var elems = document.getElementsByClassName('def');
alert(elems.length);
while(elems[0]) {
elems[0].parentNode.removeChild(elems[0]);
}
</script>
</head>
<body>
<h1>This is a title</h1>
<p>Sample paragraph</p>
<p>Another sample paragraph</p>
<p class="def"><p id="definition">Text</p></p>
</body>
</html>
Anyone knows what is wrong? Thanks in advance!