I am using javascript to edit the contents of an element depending on the browser. It is a checkbox that in all modern browsers can be clicked to reveal extra content, but not in IE8 or earlier.
However, the element I am wishing to change is echo'd via php, and I can't get the content to change. The JS file does however, mean the rest of my page doesn't appear.
The element is in the first line of my code below - . The intention is to replace the content of this element with a simple link, meaning that users of IE8 and earlier who will not be able to use the checkbox to see the hidden content, will be able to view it on another page.
Here's some code
echo "<p id=\"browser\">";
echo "<div class=\"resultsContainer\">";
echo "<input type=\"checkbox\" name=\"show\" class=\"show\">
<label for=\"show\">Recent Results</label>
<article class=\"small\">
<table class=\"results\">";
$query2=$database->query("SELECT team_name, team_score,
opposition_score, opposition_name from results_a ORDER BY
updated DESC LIMIT 0, 5");
$i=0;
while ($row2=$query2->fetch(PDO::FETCH_NUM)) {
echo ($i %2 == 0)? "<tr class=\"stripe\">" : "<tr class=\"nostripe\">";
printf ("<td>%s<td class=\"small\">%s<td class=\"small\">%s<td>%s</tr>",
$row2[0], $row2[1], $row2[2], $row2[3]);
$i++;
}
echo "</table>";
echo "</article>";
echo "</div>";
echo "</p>";
echo "<br>";
?>
<!--[if lt IE 9]>
<script src="oldBrowser.js"</script>
<![endif]-->
<noscript>
<!--[if lt IE 9]>
<p>To view results you must either upgrade Internet Explorer to
IE9 or 10, or enable ActiveX Controls on this page</p>
<![endif]-->
</noscript>
And the JS...
var browser = document.getElementById("browser");
browser.innerHTML = "<a href='results.php'>See results</a>";
Is it something to do with my code being in PHP?
>closing the<scripttag.<p>tag will get closed when the<div>starts – in effect<p id="browser">will be empty. That closing<p>tag is somewhat confusing if that is the intention. Recommend validator.w3.org