1. Back To Blog

Explain important Jquery selectors? (Jquery Interview Questions)

You can select HTML elements using Jquery in the following ways:-


Select all


Below is a simple code snippet which selects all elements and hides them.


$("*").hide();


Select by Element


Below code selects all paragraph element tags in the HTML and hides them.


$("p").hide();


Select by ID


If your HTML elements have id's like the below HTML code and you want to select the same by id.


<p id="p1">Some Para</p>


Below is how the Jquery code by ID selection code would look like.


$("#p1").hide();


Select by class


If your HTML element has class names and you want to select them in jquery using them you need use the dot followed by the classname as shown in the below code.


<p class="class1">Some Para</p>

 

$(".class1").hide()


Select by class and element


Consider the below HTML code where we have elements with "class" names.


<p class="c1">para 1</p>

<p class="c1">para 2</p>
<p class="c2">para 2</p>

<p class="c2">para 2</p>

 


So if you wish to select by "element" and "class" in Jquery your selector code becomes something as below.


$("p.c1").hide();


Below is youtube video created by questpond.com team who provide .NET Learning videos for interview preparation. The below video explains what is Jquery with simple example.


Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social