1
var $parent = $('<p>').addClass('exanple-class').prop('id','id-parent').appendTo('body'); 

I partially understand the statement above, but why declare the variable prefixed with dollar sign ? Why not use var parent = somecode, I've searched and cant find a definition

2
  • It's just a naming convention to show that the variable contains a jQuery object. The $ provides no other value. Commented Jun 2, 2015 at 16:22
  • stackoverflow.com/questions/205853/… Commented Jun 2, 2015 at 16:22

1 Answer 1

2

It's somewhat of a convention. It lets you know, without having to go back to check where the variable was declared, that it contains a jQuery object.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.