1/14 - Creating HTML Elements


#1



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


$(document).ready(functions(){
var $hs1 = $("<h1>Hello</h1>");

});


#2

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


#3

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.


#4

where i miss the code?
$(document).ready(function(){
var $h1=$("

hello

");
});

#5

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,
Sarah


#6

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".


#7

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

Many thanks again.


#8

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