Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBethany Maxfield
2,944 Pointsdocument.write to specific location on your page?
I was curious... i wanted to add this little bit of javascript to the beginning of an about me page I'm making, just for fun. I have my html and CSS all set up and looking the way I want. If I insert the <script src="story.js"></script> in the place where I want it in the html document, it prints the story outcome in the correct place, but the html and CSS doesn't full load before hand, leaving weird styling while the user is inputing information (ie, just the header loads and the google font doesn't load before the script starts etc).
Is there a way to have the HTML and CSS load first (like putting the script tags at the bottom) but pointing the document.write output to a specific place on the page? Is this possible? Or am I looking at a much more complicated solution to this problem? I'm suepr beginner at this. My JS does work, on it's own, this is just a question about linking and placement.
Thank!
1 Answer
Seth Kroger
56,414 PointsLet me tell you a little secret here about document.write(). Nobody actually uses it. Consider document.write() to be your training wheels to introduce you to JavaScript and programming. It let's you do output in a simple fashion so you can concentrate on the basics before moving on to the usually way of putting output to a web page, called DOM manipulation. With DOM manipulation you can select and change HTML elements in the document. You'll be introduced to it soon enough as you follow the lessons, along with the ins and outs of script placement, etc.
Bethany Maxfield
2,944 PointsBethany Maxfield
2,944 PointsThank you Seth, that actually makes a lot of sense. I looked at a few other places before posting here to see if I could find an answer on my own and every question similar to mine, the answer got complicated REALLY fast and didn't involve document.write. So thank you for your response! For the context of my project, I'm letting it be what it is for now.
Thanks!