I have (what I thought) was a pretty simple JS script in order to display elements based on the page ID. Works fine in FF but not Chrome or IE
Every page on the site I am working with has the line:
<input id="actualPageId" type="hidden" value="xxxxxxx"></input>
(where 'xxxxxx' is a unique numeric value to that page only, something like '12345').
My code is basically:
<div id="divToHide1" style="display: none;">blah blah blah</div>
<div id="divToHide2" style="display: none;">blah blah blah</div>
......
<script>
var checker = document.getElementById('actualPageId').value;
if (checker == 'xxxxxxx' ) {
document.getElementById('divToHide1').style= "display: inline";
}
if (checker == 'xxxxxxx' ) {
document.getElementById('divToHide2').style= "display: inline";
}
.......
</script>
The idea being it determines which page it is based in the value in the actualPageID input tag, and then un-hides the correct div accordingly. Works great in FF, not in any other browsers.
Use display property directly. Why complicate things?
document.getElementById('divToHide2').style.display= "inline";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.