Jump to content

document.write grief


Dogberry
 Share

Recommended Posts

var today_obj = new Date();var today_date = today_obj.getDate();var tips;tips = [];

Thereafter I have 31 tips one for each day of the month. The script ends with document.write(tips[today_date]);

 

Both JSLint and JSHint are giving me grief over the document write statement. Can anyone give me an alternative that will keep these two beasts happy and still give me what I want.

 

Many thanks for your time and efforts in advance.

 

Chris

 

Link to comment
Share on other sites

Modify the innerHTML of an element or create and append new DOM nodes to the document.

 

This.

 

I assume you're new to js so to do that I'd recommend going inserting new DOM nodes (cleaner imo).

var myText = document.createElement("span");myText.innerHTML = "This is a note";document.getElementById("my_container").appendChild(myText);

But I'd really recommend AngularJS if you're updating html. It has 2-way binding which means whenever you update a variable the view (your html) will update automatically. And whenever you update an input the controller will update. Save a lot of time and frustration.

Link to comment
Share on other sites

 

But I'd really recommend AngularJS if you're updating html. It has 2-way binding which means whenever you update a variable the view (your html) will update automatically. And whenever you update an input the controller will update. Save a lot of time and frustration.

 

that's seems like a steep learning curve to take on for someone very new to Javascript. AngularJS is good, but definitely not something to take on the beginning of one's period of development.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...