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

Peter Retvari
seal-mask
.a{fill-rule:evenodd;}techdegree
Peter Retvari
Full Stack JavaScript Techdegree Student 8,392 Points

<h1> tags in quote marks

Hey Guys,

I noticed that this time we use <h1> tag with quote marks. I'm a little bit confused. If it's HTML we should write the message like this: <h1> Hi, welcome to my site </h1> I know that we are programming in JS, but once we use HTML tag it's confusing to see the usual form between quote marks:"<h1> Hi, welcome to my site </h1>"

and the other thing: if we use "" it means that inside the content it's a text/string value. How can the HTML tag works with this?

2 Answers

Ray Karyshyn
Ray Karyshyn
13,443 Points

Hi Peter,

The reason we put <h1> tags in quotes is so we can insert HTML code dynamically with languages like JavaScript.

For example, I can insert my heading with JavaScript (notice how I put quotes around the <h1> tags):

HTML

<div id="banner">

</div>

JavaScript

// find element
var banner = $("#banner");

// thing to insert
var message = "<h1>Hi, welcome to my site!</h1>";

// insert message
banner.html(message);

JSFiddle Link