('.main') vs ('body')


#1

why is main prefixed with a ',' while body is not?


#2

Could you give an example of the code you are referring to so someone could enlighten you on it?


#3

Hi Jcamp23,

It's a dot (.), not a comma (,).
The dot represents a class name, a hash sign (#) represents an id, and nothing represents a tag name.

So, with this HTML:

<div class="example"></div>
<div id="example"></div>
<div></div>

You could select each element like this in jQuery (in order):

$('.example')
$('#example')
$('div')

If you didn't have the distinguishing character (., #, or nothing) in front of your selector, the computer wouldn't know which element you wanted to select, which would cause problems :slightly_smiling:

Does this help?


#4

Ok, thank you. This does help.

I'm doing the Build an Interactive Website tutorial where it asks you to move the menu and screen around. I don't believe it discusses element types. Is there a recommended tutorial for that?


#5

@jcamp23

I'd recommend you take these courses first:

  1. HTML & CSS
  2. Make A Website
  3. jQuery

:slightly_smiling:


#6

Hi quobogeba,

The code I was asking about was:

var main = function() {
/* Push the body and the nav over by 285px over */
$('.icon-menu').click(function() {
$('.menu').animate({
left: "0px"
}, 200);

$('body').animate({
  left: "285px"
}, 200);

});


#7

Ok, thanks for the recommendation!


#8

@jcamp23 As @zystvan stated above, the reason you don't select "body" as ".body" is because it wasn't assigned a class. If you were to give a <div></div> a class, being whatever you like, but I'm gonna give mine the class of 'div', it would look like this <div class="div"></div>. Now, when you select that in jQuery, it will look like this: $('.div'), and if you were to leave it without a class, you would select it like so: $('div').

I hope this helps even just the smallest bit.