1/14 - Creating HTML Elements


I keep getting the same error no matter what:
Oops, try again. Did you create a variable called $h1?

var $hs1 = $("<h1>Hello</h1>");



In jQuery, you don't use "var" to declare a variable.


As far as I see your mistake is the following one:

You typed "var $hs1 = $....." when it says "$h1".

Delete that "s" and try it again.


where i miss the code?
var $h1=$("




Hi, sorry to ask but where you say "In jQuery, you don't use "var" to declare a variable", why then, in previous lessons have we been told that to create a variable we must use the "var $p" (as an example from jQuery Functions and Selectors)? Sorry again if I'm confusing the situation, I just got stuck on the same question as the one mentioned about creating HTML elements.

Thanks you your help, I have now managed to get passed that lesson but it has left me a little confused as to why we don't use the "var" here?

Kind Regards,


It isn't necessarily needed so much as is helpful. If I'm not mistaken though, this exercise didn't want the use of "var".

I would recommend this stack overflow topic over the optionality (is that made up? I think so) of the use of "var".


Ahh, okay, many thanks. That link was really useful and I have added to my bookmarks.

Many thanks again.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.