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 trial

JavaScript

How to I automatically format text (asign classes/elements to parts) loaded with AJAX from a text file?

I have a personal Website that's only accessible by myself and learned how to load text from a txt file into a HTML file with AJAX.

This is great and exactly what I've been looking for to organise my site, but now I wonder how I can markup the text in my txt file so that parts automatically get assigned CSS classes or put into HTML elements.

How is this done?

Thank you :)

1 Answer

Steven Parker
Steven Parker
231,264 Points

When you load your text file into your page, where do you put it? If you place it into the innerHTML property of an existing element, then any markup it contains should automatically be rendered as HTML and styled using the appropriate CSS rules.

If that doesn't resolve your issue, try sharing your code here to facilitate analysis and more specific answer.