85
rated 0 times
[
87]
[
2]
/ answers: 1 / hits: 43955
/ 11 Years ago, sun, january 12, 2014, 12:00:00
I have a JavaScript function that uses document.write()
to write to the page. My issue is that when I click the button to call the function, document.write()
replaces what I already had with what I am writing. Is there a way to write text to a specific div from JavaScript?
Here is my HTML code:
<html>
<head>
<link href=style.css rel=stylesheet type=text/css>
<script type=text/javascript src=javascript.js>
</script>
<script>
// Calling the Google Maps API
</script>
<script>
<!-- JavaScript to load Google Maps -->
</script>
</head>
<body>
<div class=content>
<div id=googleMap></div>
<div id=right_pane_results>hi</div>this -->
<div id=bottom_pane_options>
<button onclick=todaydate();>Try It</button>
</div>
</div>
</body>
...and my JavaScript code (something I got from the internet just to test):
function todaydate() {
var today_date = new Date();
var myyear = today_date.getYear();
var mymonth = today_date.getMonth() + 1;
var mytoday = today_date.getDate();
document.write(<h1> + myyear + / + mymonth + /+mytoday + /h1>);
}
I would like the text to be right below the button. Any help would be appreciated.
Thanks,
Josh
More From » html