Updating Web Text Content (JavaScript)


My original Countdown blog post mentioned that the JavaScript could be used to update content on a webpage (e.g. the countdown could countdown in real time and update on a page as it does so). I touched upon a method to do this, however I will expand a little bit on it here:


// writes the message
var message=’There are ‘+days+’ days until the event!’;
The above method runs the script and posts the “message” where the script ran. It works okay for small scripts that only update one section of a page.
The below method looks through the HTML of the page for an element with the element ID of p1 and then updates p1’s content with the message.
// updates the element with the name p1
var update_P1=document.getElementById(‘p1’)
For this method to work the JavaScript .js file still needs to be linked, preferably in the HEAD section of the HTML file.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.