Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Web Developer Interviews:BootstrapFront End Web DeveloperHTML DeveloperHybrid Application DeveloperInternee PHP DeveloperJnr PHP/Codeigniter DeveloperJunior Developer PHPLaravel PHP DeveloperPython DeveloperRuby DeveloperTypographyWeb Developer & DesignerWeb Developer Cum SEO AnalystWeb Development NinjasWebsite DeveloperWordPress Themes Developer
Copyright © 2018. All Rights Reserved
Web Development Ninjas Interview Question:
Explain me difference between ID selector and class selector in jQuery?
Submitted by: MuhammadIf 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
$('#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
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.