Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6611557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:59:06+00:00 2026-05-25T19:59:06+00:00

Okay, this may be a silly question but I’m still on my path to

  • 0

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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:59:07+00:00Added an answer on May 25, 2026 at 7:59 pm

    Calling myObject.write() returns the value. Since you’re not catching and processing the return value, nothing happens.

    Another method to write content to your document:

    <body>
    <script>document.write(myObject.write())</script>
    ...</body> <!--document.write ONLY works as desired when the document loads.
           When you call document.write() after the document has finished initiating,
           nothing will happen, or the page unloads-->
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this may be a simple question but I have yet to come with
Okay, this may seem silly, but on an ASP.NET .ascx control, I'm trying to
Okay, this may be a dumb question, but I've not been able to find
Okay this may sound silly, but I am not very familiar with XML. What
Okay, this may sound silly but stay with me. I am packaging a Wordpress
Okay this may seem too simple of a question but I've wasted enough time
Okay, this might seem like a weird question, but bear with me. So I
Okay, so this one may be difficult but I will do my best to
Okay this is definitely a n00b question but here goes. The way I understand
Okay this is definitley an easy question and a stupid one but since I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.