Uncaught Typeerror:cannot Set Property ' onclick ' of NULL;
a word "make sure that the DOM node rendering of the Click event is performed prior to JS." Solution
Write a paragraph of their native JS Click event, JS code is written in the home page
<script type= "Text/javascript" > var all_features = document.getElementById ("All_features");
var all_features_down = document.getElementById ("All_features_down");
All_features.onclick=function () {var price_content = document.getelementsbyclassname ("price_content");
for (var i = 0; i < price_content.length i++) {price_content[i].style.display = "none";
} All_features.style.display = "None";
All_features_down.style.display = "block";
}; All_features_down.onclick=function () {var price_content_down = document.getelementsbyclassname ("Price_conten
T ");
for (var i = 0; i < price_content_down.length i++) {price_content_down[i].style.display = ' block ';
} all_features.style.display = "block";
All_features_down.style.display = "None";
}; </script>
The code is nothing to see, the key is that I clicked the DOM did not in the home page, but also the wood is rendered out, so reported the above error (although it is wrong, but the user is no sense, no impact, the user clicked on the page, so it can be normal operation).
But the programmer's cleanliness (no error):
Changed it into
function trigger_switch_up () {
var price_content = document.getelementsbyclassname ("price_content");
for (var i = 0; i < price_content.length i++) {
Price_content[i].style.display = ' none ';
}
All_features.style.display = "None";
All_features_down.style.display = "block";
function () trigger_switch_down{
var price_content_down = document.getelementsbyclassname ("price_content");
for (var i = 0; i < price_content_down.length i++) {
price_content_down[i].style.display = ' block ';
}
All_features.style.display = "block";
All_features_down.style.display = "None";
};
<div onclick= "Trigger_switch_down ()" >some Content</div>