I was wondering if anyone could help me with this simple code. I am trying to make a banner at the top of a web page for a cookie policy (click to agree, etc.). I have encoded part of PHP and it does and detects if the cookie policy is consistent, however I am having problems using the JS fragment to load the banner at the top of my page.
This is what I use to display this field, and the code example works fine by displaying a hyperlink or text (as shown below), but if I try to add any other type of HTML, such as a table like this, not works.
<table> <tr> <td>Test</td> <td>Table </td> </tr> </table>
Sorry updated hyperlink works
<script type="text/javascript"> function changeText() { document.getElementById("new_coder").innerHTML = '<a href="#">sdsd</a>'; } </script> <b id='new_coder'>Good Bye World</b> <input type='button' value='Change Text'/>
This is what I'm trying to do.
<!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <script type="text/javascript"> function changeText() { document.getElementById("new_coder").innerHTML = '<table> <tr> <td>Test</td> <td>Table </td> </tr> </table>'; } </script> <b id='new_coder'>Good Bye World</b> <input type='button' onclick='changeText()' value='Change Text'/> <body> </body> </html>
Is there a better feature for loading HTML snippets into a page using JavaScript. Sorry, I'm a bit sketchy in this area.
Thanks Debs
source share