2016-04-03 10 views
0

私はカスタムドロップダウンメニューを作成しようとしていましたが、これを行う方法はさまざまでした。しかし、appendChildは突然動作を停止しました。私はクロームコンソールをチェックしたときに、 "Uncaught TypeError:26行目の" appendChild 'のnullを読み取ることができませんでした。私は以前にappendChildを多用していましたが、この種の問題は一度もありませんでした。私は以前に作った別の文書を開いて、ほぼ同じ行をコピー&ペーストして同じエラーを出しました。助けて?appendChildは特定のドキュメントでは機能しません

<!doctype html> 
<script> 
function changeClassValue() { 
    if(document.getElementById('dropDown').className == "up") { 
      document.getElementById('dropDown').className = "down"; 
      numberValue = 1; 
     } else if(document.getElementById('dropDown').className == "down") { 
      document.getElementById('dropDown').className = "up"; 
      numberValue = 0; 
     } else { 

    } 
changeTextVisibility(); 
} 
function changeTextVisibility() { 
    if(numberValue == 1) { 
      newDiv.appendChild(newParagraph); 
    } else if(numberValue == 0); { 
      newDiv.appendChild(newParagraph); 
} 
} 
var numberValue; 
var newDiv = document.createElement('div'); 
var newParagraph = document.createElement('p'); 
var newParagraphText = document.createTextNode('This is a drop down menu!'); 
document.body.appendChild(newDiv); 
newParagraph.appendChild(newParagraphText); //this is line 26, and is what seems to be broken. 
</script> 
<style> 

</style> 

<body style="background-color: skyblue;"> 
<p id="dropDown" class="up" style="font-size: 25px; padding: 10px  10px;background-color: slategray; display: inline-block;" 
onclick="changeClassValue();"><strong><u> >drop down menu< </u></strong></p> 
</body> 

答えて

関連する問題