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 jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 2

Bryan Castleman
Bryan Castleman
9,520 Points

Why are singular quotation marks used when assigning a variable to a div ?

in the following: var $overlay = $(' ') ?

1 Answer

Hi Bryan,

In this case single quotes were used to wrap the string because it contains double quotes which were used for the id attribute.

You could wrap with double quotation marks on the outside but then you have to escape the double quotations marks on the inside with a backslash \

var $overlay = $("<div id=\"overlay\"></div>"); This is coming at the expense of readability

Alternatively, you can use double quotes on the outside and single quotes on the inside:

var $overlay = $("<div id='overlay'></div>");

Bryan Castleman
Bryan Castleman
9,520 Points

I see. Thanks for clearing that up.