jQuery Interview Questions and Answers (185) - Page 8

How to Add multiple classes to any controls dynamically?

More than one class may be added at a time,separated by a space,to the set of matched elements like below code:-
<script src="//code.jquery.com/jquery-1.10.2.js"></script>

$("p").addClass("class1 class2");

Here class1 and class2 are 2 separate classes.
How to Remove class to any controls dynamically?

removeClass is an in-built jQuery method,which is used for removing any class dynamically.We have to pass class name in this removeClass method .
Syntax:-
removeClass(className);

For Example:-
<script src="//code.jquery.com/jquery-1.10.2.js"></script>

$("p").removeClass("className");

How to Remove class to any controls dynamically?

removeClass is an in-built jQuery method,which is used for removing any class dynamically.We have to pass class name in this removeClass method .
Syntax:-
removeClass(className);

For Example:-
<script src="//code.jquery.com/jquery-1.10.2.js"></script>

$("p").removeClass("className");

How to check/uncheck a Checkbox control or radio button using jQuery?

Using the Prop method,we can achieve:-
To Check #rdb_active buttons
$("#rdb_active").prop("checked",true);

To Uncheck #rdb_active buttons
$("#rdb_active").prop("checked",false);

Similarly,we can use Checkboxes.
How to disable/enable a radio buttons or check boxes?

We can enable or disable a radio buttons or check boxes using the .prop() method.We have to write disabled property in prop method.
For Example:-
//To Disable controls
$("#control_id").prop("disabled",true);

//To Enable controls
$("#control_id").prop("disabled",false);


Where,control_id is your checkbox/radio buttons id.
How to check jQuery version?

jQuery keeps track of the current version of the script being used in jQuery.fn.jquery property. Both major version version 1.x and version 2.x have this property.

jQuery.fn.jquery;

It will return string: "1.10.2"

What is the shorthand for jQuery to get Version?

Since jQuery == $,so we can use shorthand syntax as
$.fn.jquery;

This will return the same version.
What is the alternate method to get Version?

Write below code:-
jQuery().jquery;


OR shorthand method
$().jquery;

How can we check the Loaded jQuery UI Version?

Returns jQuery UI version For ex: 1.8.2 or undefined
$.ui.version

What is the alternative way of checking Loaded jQuery UI Version?

Write below code to check Loaded jQuery UI Version as:-
jQuery.ui.version;

How to remove bottom/last table row using jQuery?

We can write below simple code for bottom row removal as:-
$('#tbl tr:last').remove();

Where #tbl is Htmltable ID.
How to remove n'th or 5rd row from the table using jQuery?

Simply write below code:-
$('#tbl tr:eq(4)').remove();

Where 4 is the table index.
How to get the Number of Controls Count using jQuery.

jQuery has Length property through which we can find the number of controls
Suppose,we have following HTML structure as shown below:-
<div id = div_1" class = "class1">

<div id = div_2" class = "class2">container 1</div>
<div id = div_3" class = "class2">container 2</div>
</div>

$('.class1').length;
Output:- 1
$('.class2').length;
Output:- 2

How to change CSS background image with jQuery?

Write below code:-

$('#div_project').css('background-image', 'url(my_image.jpg)');

What is an alternative way of changing CSS background image with jQuery?

Just write below code:-
$('#div_project).css('background','url(path/to/image.jpg)');

How to add class to the last selected paragraph element and highlighting it.

<!doctype html>

<html lang ="en">
<head>
<meta charset="utf-8">
<title>addClass demo</title>
<style>
p
{
margin: 8px;
font-size: 16px;
}
.selected
{
color: red;
}
.highlight
{
background: yellow;
}
</style>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<p>DotNet</p>
<p>Funda</p>
<p>Website</p>
<script>
$("p:last").addClass("selected highlight");
</script>
</body>
</html>

How to set target of the first anchor tag link only?

Using the prop property of jQuery , we can do as:-
$('a').prop('target','_blank');

How to set the target of all anchor tags in the Loop using jQuery?

Write below code:-
$('a').each(function(){

$(this).prop('target','_blank');
});

What is the key points about IDENTITY_INSERT command?

We have following key points about IDENTITY_INSERT command :-

1). It can only be enabled on one table at a time.If we try to enable it on a second table while it is still enabled on a first table,then Sql Server will generate an error.
2). When it is enabled on a table we must specify a value for the identity column.
3). The user issuing the statement must own the object,we must have to be a system administrator or having a sysadmin role,be the database owner (dbo) or be a member of the db_ddladmin role in order to run the command.
How to get the number of items to be executed on a pirticular element ?

NOTE: This is objective type question, Please click question title for correct answer.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories