Quantcast
Channel: Excellent Web World » JQuery
Viewing all articles
Browse latest Browse all 10

Jquery Interview Question

$
0
0

Q.1 What is Jquery?

Ans: jQuery means jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, animating, event handling, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. jQuery is build library for javascript no need to write your own functions or script jQuery all ready done for you

————————————————————————————————————–
Q.2 How to Check or Uncheck All Checkboxes using jquery?

Ans:There are different methods to check and uncheck the check boxes.

suppose that you have checkboxes like that

<input id="”Items1″" type="”checkbox”" name="”Items”" value="”1″" />
<input id="”Items2″" type="”checkbox”" name="”Items”" value="”2″" />
<input id="”Items3″" type="”checkbox”" name="”Items”" value="”3″" />
<input id="”Items4″" type="”checkbox”" name="”Items”" value="”1″" />

1- using attr() function.
$(‘#checkall’).click(function(){
$(“input[@name='Items']:checked”).attr(‘checked’,true);
});
$(‘#uncheckall’).click(function(){
$(“input[@name='Items']:checked”).attr(‘checked’,false);});

2- using attr() and removeAttr()functions
$(‘#checkall’).click(function(){
$(“input[@name='Items']:checked”).attr(‘checked’,true);
})
$(‘#uncheckall’).click(function(){
$(“input[@name='Items']:checked”).removeAttr(‘checked’);})

Note- if your checkbox name is array type, then simple replace Items to Items[].
————————————————————————————————————–


Q.3 How to fetch the values of selected checkbox array using JQuery?

Ans:
Suppose that below is checkbox array.

<input id="”Items1″" type="”checkbox”" name="”Items[]“" value="”1″" />
<input id="”Items2″" type="”checkbox”" name="”Items[]“" value="”2″" />
<input id="”Items3″" type="”checkbox”" name="”Items[]“" value="”3″" />
<input id="”Items4″" type="”checkbox”" name="”Items[]“" value="”1″" />

and we want the get the value of selected checkbox using jquery.then simple use below code.

var selItems = new Array();
$(input[@name='Items[]‘]:checked”).each(function() {selItems .push($(this).val());});

Here selItems will take all selected value of checkbox.
————————————————————————————————————–
Q.4 How we can apply css in multiple Selectors in jquery.

Here to take effect is example to demonstrate.
$(“div,span,p.myClass”).css(“border”,”1px solid green”);
the border will be apply in all div,span ,p.myClass class element.
————————————————————————————————————–
Q.5 How can we apply css in div using jquery.

using css() method we can apply css in div element.
example:
$(“div”).css(“border”,”1px solid green”);
————————————————————————————————————–
Q.6 How can we check/uncheck an input in jquery?

Using two function, we can perform the operation.
// Check #x
$(“#checkboxid”).attr(“checked”, “checked”);
// Uncheck #x
$(“#checkboxid”).removeAttr(“checked”);

————————————————————————————————————–
Q.7 How can we disable/enable an element in jquery?

you can disable/enable web element using attr and removeAttr functions respectively.
// Disable #x
$(“#x”).attr(“disabled”,”disabled”);
// Enable #x
$(“#x”).removeAttr(“disabled”);
————————————————————————————————————–
Q.8 How do I test whether an element has a particular class?

* You can use the is() method along with an appropriate selector

if ( $(‘#myDiv’).is(‘.pretty’) )
$(‘#myDiv’).show();

Note that this method allows you to test for other things as well. For example, you can test whether an element is hidden (by using the custom :hidden selector):

if ( $(‘#myDiv’).is(‘:hidden’) )
$(‘#myDiv’).show();

The post Jquery Interview Question appeared first on Excellent Web World.


Viewing all articles
Browse latest Browse all 10

Trending Articles