Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Write code to get browser name

Answer»

Below is the code to GET the browser name here i have USED if else to find the browser

$(document).READY(function() {
if ($.browser.mozilla && $.browser.version >= "2.0" ){
ALERT('Mozilla version is above 1.9');
}

if( $.browser.safari ){
alert('Browser is of Safari');
}

if( $.browser.opera){
alert('Browser is ofOpera');
}

if ($.browser.msie && $.browser.version <= 6 ){
alert('Version is IE 6 or below version');
}

if ($.browser.msie && $.browser.version > 6){
alert('Vsersion of IE is above 6');
}
});

2.

What are Selectors in jQuery mean and its syntax

Answer»

When we have to WORK with any control on a web page we need first to find the control. For that we USE document.getElementByID or document.getElementByName. But in jquery we do it using SELECTORS. Using this selectors we can select all the controls as well using a symbol (* ) .Below is the syntax for the same:-
< script language="JAVASCRIPT" type="text/javascript">
$("*").css("border", "9px BLACK");
< /script>

with above code we can set all the border with black and fonr is 9px

3.

Disable or stop cut copy paste on texbox using jQuery

Answer»

Below is code which stop user to cut copy and paste data in textbox USING jquery.Becasue it will be better if we do not allow users to copy paste the data entered in Email and Confirm Email FIELD in order to make the user to type themselves.


< script SRC="_scripts/jquery-1.4.1.min.js" type="text/javascript" >< /script>
< script type="text/javascript">
$(function() {
$("#< % =txtname.ClientID %>,#< % =txtaddress.ClientID%>").bind("cut copy paste", function(event) {
event.preventDefault();
});
});
< /script>
< /head>
< body>
< form ID="form1" runat="server">
< div>
< b>EnterName < /b>< asp:TextBox ID="txtname" runat="server">< /asp:TextBox>< br />
< b>Address < /b>< asp:TextBox ID="txtaddress" runat="server">< /asp:TextBox>

4.

How to get current url from jQuery

Answer»

To get the current URL from jquery we NEED to write the below syntax.

< script&GT;
$(document).ready(function ($)
{
ALERT(window.location);
});

< /script>

5.

Can we add or change text in span tag with the help of jQuery?

Answer»

Can we ADD or CHANGE text in span tag with the HELP of JQUERY?
Yes we can change the text in between span tag and add both html and text data in span tag with the help of jQuery. Below is the syntax for the same:-


jQuery for Span

6.

JQuery code to search some sepecific data from dropdownlist and select if found in JQuery?

Answer»

JQuery code to search some sepecific data from DROPDOWNLIST and select if FOUND in JQuery?
Below is the code to search some ELEMENT in dropdownlist from jQuery and then select that SPECIFIC value.
HTML Code


dropdownlist

Jquery Code


jQueryCode dropdownlist

7.

Difference between length and size in jQuery?

Answer»

Difference between length and size in jQuery?
Both os these are used to find the NUMBER of elements in an object. Here Length is MUCH faster then size. And the REASON BEHIND this is that length is a property and size is method. Because properties are faster then method.

8.

Write code in jQuery to create back button

Answer»

Below is the code to go back to LAST visited page in the browser

< script TYPE="text/javascript"&GT;
$(FUNCTION()
{
$('#back').click(function() {
parent.history.back();
return FALSE;
});
});
< /script>

9.

Which jQuery method should be used to deal with name conflicts?

Answer»

Which jQuery method should be used to deal with name CONFLICTS?
CHOOSE the CORRECT option from below list
(1)CONFLICT()
(2)noConflict()
(3)noNameConflict()
(4)nameConflict()

Answer:-(2)noConflict()

10.

What is significance of jQuery.NoConflict

Answer»

If we are referring any other script files along with jQuery you may get CONFLICTS in the namespace. Some times if we use jQuery with any other libraries, we may get clash between two libraries and we encounter situations like NEITHER of the functionality works.

Important THING to keep in mind is , when we call .noConflict() jQuery will return $() to it s previous owner .So we need to use jQuery() instead of $() function.

The following example illustrated how to use no conflict . This can be used in cases where one script works with out the other and will not work when both the scripts are combined .




JQuery

The jQuery library and all plugins are within the jQuery namespace. But "global" objects are stored INSIDE the jQuery namespace . so It is usual to get namespace clash between jQuery and any other library or plug-in. $ is just short cut for jQuery. Hence OVERRIDING $ function will work.

You can also assign in another variable and use it in the application like this as shown below.



JQuery NoConflict

11.

What is jQuery Connect and where to use it

Answer»

This is a jQuery plugin that is used to connect / bind a function to another function. It is more of assigning a handler for another function. Connect is used to execute a function whenever a function from another OBJECT or plugin is executed. We can connect to an event of a DOM element too using this function. In the sense same connect function can be used for both DOM ELEMENTS and for the functions.


$.connect(refobj,refFuncName, connObj,connFunc);

This means that, when the reference function is executed, the connected function gets executed automatically after it. To understand more please analyze the FOLLOWING EXAMPLE



Jquery connect

Here we connected "FUN2" of object b to "fun1" of object a. When we call b.fun2, a.fun1 will also execute automatically.

12.

Write down the query to validate Pan Number

Answer»

Below query is the JQUERY which help us to validate the PAN number wheather it is correct or not



$(document).ready(function{
function ValidatePAN()
{
VAR panno=$("#txtPan").VAL();
var regpanno = /^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/;

if(regpanno.test(panno) == false)
{
$("#errormsg").val('pan number is incorrect');
}
ELSE
{
$("#errormsg").val('pan number is correct');
}
}
});

13.

Write a example for jquery.grep method run on json array

Answer» WRITE a example for jquery.grep method RUN on JSON array
Below is the example for jquery.grep method which APPLY filter on the json array

var dataarray = {
"itemval": [{
"id": 1,
"category": "option1"
}, {
"id": 2,
"category": "option2"
}, {
"id": 3,
"category": "option1"
}]
};

var returnedvalue = $.grep(dataarray.itemval, function (element, index) {
return element.id == 1;
});
alert(returnedvalue[0].id + " " + returnedvalue[0].category);
14.

How to show and hide DIV tag with the help of jQuery

Answer»

Below is the code for show and hide the DIV tag by using jquery

< html xmlns="http://www.w3.org/1999/xhtml">
< head>
< title>DIV Tag Show and Hide with jQuery< /title>
< script TYPE="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js">< /script>
< script type="text/javascript">
$(function()
{
$('.showhide').click(function() {
$(".divtagcss").slideToggle();
});
});
< /script>
< style type="text/css">
.divtagcss{
width: 30%;
padding:20px;
background:#EB5E00;
color:#fff;
margin-top:10px;
border-bottom:5px solid #FFF;
DISPLAY:none;
}
< /style>
< /head>
< body>
< a HREF="#" class="showhide">Show and hide< /a>
< div class="divtagcss">
Here is the jquery in getproductprice.com
Here is the jquery in getproductprice.com
Here is the jquery in getproductprice.com
Here is the jquery in getproductprice.com
< /div>
< /body>
< /html>

15.

validation in jQuery to get only alphabets in textbox

Answer»

Below code will helps to APPLY validation on textbox which only accept ALPHABETS not any numeric or special character

$(function ()
{
$('#txtNumeric').KEYDOWN(function (e)
{
if (e.shiftKey || e.ctrlKey || e.altKey)
{
e.preventDefault();
}
else
{
var key = e.keyCode;
if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key &LT;= 40) || (key >= 65 && key <= 90)))
{
e.preventDefault();
}
}
}
);
});

16.

JQuery code to empty div tag values

Answer»

Below is the TWO line code to empty the div tag text value here below is the JQUERY function

< script>
$(document).ready(function(){
$("button").click(function(){
$("#divId").empty();
});
});
< /script>


Now comes to Html PART of code here i have add 1 div tag and some text in it and a button to clear the text in div tag


< div id="divId" style="height:50%;width:50%;border:1px solid black;background-color:Red;">

welcome to WEBSITE crackyourinterview.com
< p>This site helps you to crack your interview.< /p>
< p>This site contains some good interview tips and questions.< /p>
< /div>
< br>
< button>Click to Empty< /button>

17.

What are the Functions in jquery and its type

Answer»

The FUNCTION in JavaScript are of two type either named or anonymous. As the NAME suggest A named function can be defined using function KEYWORD as given below
function nameoffunction(){
// do some code here
}


On the other hand an anonymous function can be defined in same WAY as we defined normal function but it doesnot have any name. We can use anonymous function to assigned to a variable or passed to a method as given below.

var handlerVar = function (){
// do some code here
}

18.

Can we do SlideToggle Effects in jQuery

Answer»

Yes we can do slidetoggle effects in JQUERY and METHOD of this is given below

< script TYPE="text/javascript" >
$(document).READY(FUNCTION()
{
$("#div_slide_toggle").slideToggle('slow');
}
);
< /script>

19.

Write code to disable cut copy and paste

Answer»

Below is the code to disable CUT copy and paste . Here code is of jquery by simply writing the code


$(document).READY(function(){
$('#txtInputId').BIND("cut copy paste",function(E) {
e.preventDefault();
});
});

20.

Code to bind dropdownlist with ng options

Answer»

Below is the code to bind the dropdownlist with ng OPTION here i have use case statement to bind the dropdownlist

$lt;script type="text/javascript"$gt;
VAR appExample = angular.module('Examplesampleapp', [])
appExample.controller('Examplecontrol', function ($FunctionScope) {
$FunctionScope.sample = [{
id: '1',
name: 'JavaScript FAQ'
}, {
id: '2',
name: 'JQuery Faq'
}, {
id: '3',
name: 'AngularJS Faq'
}];
});
$lt;/script$gt;
$lt;/head$gt;

$lt;body data-ng-app="Examplesampleapp" data-ng-controller="Examplecontrol"$gt;
$lt;form id="form1"$gt;
Select Name: $lt;select ng-options="s.id as s.name for s in sample" ng-model="col"$gt;
$lt;option VALUE=""$gt;--Select--$lt;/option$gt;
$lt;/select$gt;

21.

How to use jQuery libarary and call function from it

Answer»

To use jQuery we need to simple add below LINE in our HTML code file which is as below

< script type="text/javascript" SRC="/jquery/jquery-1.3.2.min.js">< /script>

And to call function from it we need to use below code

< script type="text/javascript" language="javascript">
$(DOCUMENT).READY(function()
{
$("div").click(function()
{
alert("Hello world!");
});
});
< /script>

22.

Code to get browser version in jQuery

Answer»

Below code will help us to get browser version which are we USING currently for our page

< script TYPE="text/javascript" src="/jquery/jquery-1.3.2.min.js"&GT; < /script>
< script type="text/javascript" LANGUAGE="javascript">
$(document).READY(function()
{
jQuery.each(jQuery.browser, function(i, val)
{
$( i + " : " + val ).appendTo(document.body);
});
});
< /script>

23.

Process of jQuery works

Answer»

AS all of us know $() function is an ALIAS for the jQuery() function we can also use jQUery instead of $ and this RETURNS a special Java-Script object. And this Object contains an array of DOM elements that matches the selector. And this Selector is key thing in jQuery development. It is away to select node from DOM. This Java-Script object possesses a large NUMBER of useful predefined methods that can action group of elements.This type of construct is termed a wrapper because it wraps the matching element(s) with extended functionality.

(1)$(object) is called jQuery wrapper around the object.
(2)jQuery has a ready element that checks the document and waits until document is ready to be manipulated.
(3)It searches for the reference files for framework, once it FINDS it then control GOES to the function specified.
(4)What ever code mentioned in the function that gets executed. Event handling also can be implemented here.



Jquery works


we can debug the jquery script by placing debugger keyword (OR) attaching worker process and then inserting a break point .

24.

Example of JQuery focus event on textbox

Answer»

Below is the example for JQuery to change COLOUR of textbox on foucs on it.First we take a html CONTROL and do jquery on it.

< input id="Inputtxt" type="text" />

JQuery script for changing BACKGROUND COLOR on receiving focus

< script language="javascript" type="text/javascript">
$(document).ready(function () {

$("#txtInput1").focus(
function (EVENT) {
$("#Inputtxt").css("background-color", "Yellow");
}
);
});

25.

Difference between body.onload and document.ready in jQuery

Answer»

Difference between body.onload and document.ready in jQuery
body.onload
(1)We can use body.onload method only once in a page
(2)And this method is CALLED once the resources of page are loaded.
(3)This method will be called once the IMAGES, CSS and DOM will be done.
document.ready
(1)we can use document.ready method MANY times in same page.
(2)This method is called once DOM is ready.
(3)This method is called once DOM is ready and will not wait till other resource are loaded.

26.

Three types of selector in JQuery

Answer»

Belwo are the 3 TYPES of selector avail in jquery:-
(1)CSS Selector
(2)XPATH Selector
(3)Custom Selector

27.

Different method which provides effects in JQuery

Answer» BELWO are the methods which helps to do effects:-
(1)SHOW()
(2)Hide()
(3)Toggle()
(4)Fadein()
(5)FadeOut()