Okay, this may be a silly question but I'm still on my path to learning OO javascript like a pro, so please don't laugh if this question is a little dumb... okay, say I have a very simple object like this
var myObject = {
write:function(){
return 'this is a string';
}
}
now if add the following outside my object (please note I have the appropriate Div in my webpage):
document.getElementById('myDiv').innerHTML = myObject.write();
the innerHTML of my div is filled with the string 'this is a string', however if I just add the following to my script (outside the object): myObject.write()
nothing is returned? Can some one tell me why and how I could write to the page ( not using document.write(myObject.write()) ) to output the string to the page. If this can't be done please let me know why...
sorry if this is a really simple / stupid question but I am learning.
Here's the full thing to help...
<html>
<head>
</head>
<body>
<div id='myDiv'></div>
<script type="text/javascript">
var myObject = {
write:function(){
return 'this is a string 2';
}
}
//document.getElementById('myDiv').innerHTML = myObject.write();
myObject.write();
</script>
</body>
</html>