handover a javascript variable to html -
i have 2 files, filter.html
, filter.js
. in filter.html
have div id "test" , in filter.js
have variable name "finishedhtml".
now want write content of "finishedhtml" test div html code, html things "finishedhtml" empty. how can solve problem?
source:
var finishedhtml = "<h2>yes works</h2>"
header { display: block; background: #a2afbc; top: 0; height: 50px; position: fixed; width: 100%; text-align: center; } footer { height: 50px; width: 100%; bottom: 0px; left: 0px; background: #a2afbc; position: fixed; } .headertitle { font-size: 2.0em; font-family: verdana; font-weight: 100; color: #506b84; margin: 0em; font-weight: bold; } h2 { font-size: 3.0 em; color: red; }
<html> <head> <title>title</title> <link rel="stylesheet" href="style.css" type="text/css" > <meta http-equiv="content-type" content="text/html; charset=utf-8" > <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico" > <!--filter.js--> <script language="javascript" type="text/javascript" src="filter.js"></script> </head> <body> <header> <span class="headertitle">header text</span> </header> <div id="test" style="margin-left: 300px; padding-top: 300px;"> <h1>this test text</h1> </div> <script language="javascript" type="text/javascript"> document.getelementbyid('test').innerhtml = finishedhtml; </script> <footer> </footer> </body> </html>
thanks 4 help!
you can use variable finishedhtml
after has been declared. declare @ point before setting innerhtml
, work.
var finishedhtml = "<h2>yes works</h2>"; document.getelementbyid('test').innerhtml = finishedhtml;
header { display: block; background: #a2afbc; top: 0; height: 50px; position: fixed; width: 100%; text-align: center; } footer { height: 50px; width: 100%; bottom: 0px; left: 0px; background: #a2afbc; position: fixed; } .headertitle { font-size: 2.0em; font-family: verdana; font-weight: 100; color: #506b84; margin: 0em; font-weight: bold; } h2 { font-size: 3.0 em; color: red; }
<html> <head> <title>title</title> <link rel="stylesheet" href="style.css" type="text/css" > <meta http-equiv="content-type" content="text/html; charset=utf-8" > <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico" > <!--filter.js--> <script language="javascript" type="text/javascript" src="filter.js"></script> </head> <body> <header> <span class="headertitle">header text</span> </header> <!-- style="margin-left: 300px; padding-top: 300px;"--> <div id="test" style="margin-top: 100px;"> <h1>this test text</h1> </div> <footer> </footer> </body> </html>
Comments
Post a Comment