Explain me difference between ID selector and class selector in jQuery?

Submitted by: Muhammad
If you have used CSS, then you might know the difference between ID and class selector, It's the same with jQuery. ID selector uses ID e.g. #element1 to select element, while class selector uses CSS class to select elements. When you just need to select only one element, use ID selector, while if you want to select a group of element, having same CSS class than use class selector. There is good chance that during the interview you will be asked to write code using ID and class selector. The following jQuery code uses ID and class selectors:

$('#LoginTextBox') -- Returns element wrapped as jQuery object with id='LoginTextBox'

$('.active') -- Returns all elements with CSS class active.
From a syntax perspective, as you can see, another difference between ID and class selector is that former uses “#” and later uses “.” character. More detailed analysis and discussion, see answer.
Submitted by: Muhammad

Read Online Web Development Ninjas Job Interview Questions And Answers