Question:

How to do this in HTML?

by  |  earlier

0 LIKES UnLike

Without using a text box or input field, how can you display and change text using JavaScript?

I've tried the 'id="text"' and document. getElementById ('text'). value="hello!";. However, it didn't work. Here's the URL for the example:

http://w3schools.com/js/tryit.asp?filename=tryjs_timing_clock

 Tags:

   Report

2 ANSWERS


  1. Try this instead:

    document. getElementById ('text').innerHTML = "hello!";


  2. .value is not the right properly. You want .innerHTML. For example, put this in your page:

    <a id="z">This is the first block of text.</a>

    Then put this in your script:

    document.getElementById ("z").innerHTML="This is the second block of text."

    Be sure to delete the space I inserted between getElementById and ("z"), I added that in order to make the text appear properly on Yahoo Answers. The code should then work. You can put the Javascript text changer function inside any other function you like or make it insert any HTML you like, including tags, images, etc.

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions