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 trialEnzo Cnop
5,157 PointsI'm confused by the <h2> </h2> tags.
In the .js file, Dave writes <h2> </h2> tags around his sentences. I thought this was an HTML convention, not a javascript one. If it is a JavaScript convention, it has not yet been explained. Can someone please explain how these tags operate in JavaScript, and why Dave is placing them in his .js instead of his .html. Thanks!
4 Answers
Chris Jardine
13,299 PointsHi Enzo
<h2></h2> is a HTML tag and not javascript as you said. He passes the tags as a string to be printed in the HTML document, but when it is printed it takes on the h2 style of the document. So I could have styled the h2 like this:
h2 {
font-size: 32px;
color: red;
}
So when it is printed to the HTML document it will have a font size of 32px and the color of it would be red.
I hope this makes sense.
Chris Jardine
13,299 PointsHi Enzo
To Javascript, <h2> is just text (a string), but when it is passed to the HTML document the <h2> becomes meaningful to the HTML document and styles the text inside the tag accordingly. The <h2> tag would only be meaningful to a HTML document.
Good luck!
Cosimo Scarpa
14,047 PointsThe maximum that you can do with <h2> tag in JS is that you can select them with a code.
document.getElementsByTagName("h2");
Enzo Cnop
5,157 PointsCan you elaborate a bit / explain why Chris's answer is misleading?
Luis Roman
1,511 PointsI had taken some HTML classes before, was really confusing is why are they making people jump into this course without showing them other things first. Poor communication or education.
Enzo Cnop
5,157 PointsEnzo Cnop
5,157 PointsYes! Thank you! Just to be doubly clear -- the way you wrote it is a 'JavaScripty' way of writing the same HTML code? Also, am I correct in assuming this doesn't really matter unless you are interfacing with an HTML document?