jQuery Interview Questions and Answers
In this article, I have explained 100+ jQuery interview questions and answers with examples. I have tried to explain every possible jQuery interview question here that will help you to build your technical skill set and can help you in your interview.
-
What is jQuery?
jQuery is not a language but it is a well written code. jQuery is a set of JavaScript libraries that have been designed specifically to simplify HTML document traversing, animation, event handling, and Ajax interactions. jQuery is fast and lightweight. There are many other JavaScript code libraries such as MooTools, but jQuery has become the most popular because it is so easy to use.
-
Why do we use jQuery?
Or
What are the advantages if jQueryWe use jQuery due to following advantages:
- It is easy to use and learn.
- It helps to improve the performance of the application.
- It simplifies the task of creating highly responsive web pages.
- It helps to develop most browser compatible web page as it works across modern browsers.
- It helps to implement UI related critical functionality without writing hundreds of lines of codes.
- It abstracts away browser-specific features, allowing you to concentrate on design.
- It leverages your existing knowledge of CSS
- It performs multiple operations on a set of elements with one line of code (known as statement chaining)
- It is extensible so you can use third-party-plug-ins to perform specialized tasks or write your own.
-
How JavaScript and jQuery are different?
JavaScript is a language while jQuery is a set of JavaScript libraries that have been designed specifically to simplify work like HTML document traversing, animation, event handling, and Ajax interactions.
-
Is jQuery a replacement of JavaScript?
No, jQuery is not a replacement of JavaScript. jQuery is a set of libraries which is written on top of JavaScript and have been designed specifically to simplify work.
-
jQuery is a JavaScript library file or JSON library file?
jQuery is a library of JavaScript file.
-
jQuery library is client side or server side?
jQuery is client side scripting.
-
Consider a scenario where things can be done easily with javascript, would you still prefer jQuery?
No, if things can be done easily with css and javascript then you should not prefer jQuery because jQuery has some size and there is no point of wasting bandwidth.
-
Which operating system is more compatible with jQuery?
Windows, Mac and Linux are more compatible with the jQuery.
-
How can start work on jQuery?
First we need to download jQuery. jQuery comes in two versions:
- Development
- Production (which is compressed and minified)
jQuery file can be downloaded from jQuery Official website.
Typically, we download both versions and then use each one for its intended purpose.After downloading of jquery file, to start work on jquery, you need to add reference of that file in your webpage.
-
Whether we need to add jQuery file in both Master and Content page?
jQuery file should be added to the Master page and can use access from the content page directly without having any reference to it.
-
What is use of
$
sign?The jQuery library provides the jQuery function, which allows you to select elements using selectors.
var paragrapths = jQuery('p');
But generally when you see jQuery code then you will see that
$
sign is used mostly:var paragrapths = $('p');
$
sign in the code above is just a shorter and more convenient name for the jQuery function. Actually, in the jQuery source code, you'll find this code:
This code allows to use//Expose jQuery to the global object window.jQuery = window.$ = jQuery;
$
sign in place of jQuery keyword. -
Can we use our own specific character in the place of
$
sign in jQuery?Yes. We can use our own special character in place of
$
sign. It is possible using jQuery.noConflict(). -
What is jQuery.noConflict?
As we can use other client side libraries like MooTools, Prototype with jQuery and they also use
$()
as their global function and to define variables. This situation creates conflict as$()
is used by jQuery and other library as their global function. To overcome from such situations, jQuery has introducedjQuery.noConflict()
.jQuery.noConflict(); // Use jQuery via jQuery(...) jQuery(document).ready(function(){ jQuery("div").hide(); });
You can also use your own specific character in the place of
$
sign in jQuery.var $j = jQuery.noConflict(); // Use jQuery via jQuery(...) $j(document).ready(function(){ $j("div").hide(); });
-
Is it possible to use other client side libraries like MooTools, Prototype along with jQuery?
Yes
-
What is the difference between .js and .min.js?
Or
What is the difference between simple jquery file and minified jquery file?.min.js is basically the minified version of jQuery file. Both the files are same as far as functionality is concerned. but .min.js is quite small in size so it loads quickly and saves bandwidth.
-
What is the advantage of using minimized version of jQuery?
Minimized version is very small (approx 50% less) in size so it loads quickly, saves bandwidth and improve performance of website.
-
Why there are two different version of jQuery library?
jQuery library comes in 2 different versions.
- Development
- Production/Deployment
As jQuery is open source, the development version is useful at development time and if you want to change something then you can make those changes in development version.
But the deployment version is minified version or compressed version so it is impossible to make changes in it. Because it is compressed, so its size is very less than the production version which affects the page load time.
-
How can we debug jQuery?
There are 2 ways to debug jQuery:
- Add debugger; keyword to the line where you need to start debugging and then run Visual Studio in Debug mode with F5 function key.
- Insert a break point after attaching the process
-
What is the use of jquery-x.x.x.-vsdoc.js file?
.vsdoc file is used to provide intellisense support. We can even delete this file but if we will delete this file then we will loose the support of intellisense.
-
Which is the starting point of code execution in jQuery?
The starting point of jQuery code execution is
$(document).ready()
function which is executed when DOM is loaded. -
Can we have multiple
document.ready()
function on the same page?Yes, We can have any number of
document.ready()
function on the same page. -
Is there any difference between body
onload()
anddocument.ready()
function?These are the differences between
onload()
anddocument.ready()
:- We can have as many
document.ready()
function in a page but we can have only single onload function in one body. document.ready()
function is called as soon as DOM is loaded wherebody.onload()
function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.
- We can have as many
-
What is the difference between
window.onload
event anddocument.ready()
function? -
Is it possible to hold or delay
document.ready
execution for sometime?jQuery.holdReady()
function allows us to hold or delay execution ofdocument.ready
function. This function was introduced with release of jQuery 1.6. You need to pass value true or false in function as parameter to specify whether you want hold or resume.$.holdReady(true); $.getScript("someplugin.js", function() { $.holdReady(false); });
-
What is a CDN?
CDN Stands for Content Distribution Network or also called Content Delivery Network is a group of computers placed at various points connected with network containing copies of data files to maximize bandwidth in accessing the data. In CDN, a client accesses a copy of data nearer to the client location rather than all clients accessing from the one particular server. This helps to achieve better performance of data retrieval by client.
-
What is the advantage of using CDN?
- It reduces the load from your server.
- It saves bandwidth. jQuery framework will load faster from these CDN.
- It will be cached, if the user has visited any site which is using jQuery framework from any of these CDN
-
Which are the popular jQuery CDN?
There are 3 popular jQuery CDNs.
- Microsoft
- jQuery
-
How to load jQuery from CDN?Microsoft CDN
Google CDN<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
jQuery CDN<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.9/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
-
How to load jQuery locally when CDN fails?
It is a good approach to always use CDN but there may be a possibility (rare) that CDN is down. In that case you code will not work as jquery file will not be loaded. We can overcome this issue by following code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript"> if (typeof jQuery == 'undefined') { document.write(unescape("%3Cscript src='Scripts/jquery.1.9.1.min.js' type='text/javascript'%3E%3C/script%3E")); } </script>
It first loads the jQuery from Google CDN and then check the jQuery object. If jQuery is not loaded successfully then it will references the jQuery.js file from hard drive location. In this example, the jQuery.js is loaded from Scripts folder.
-
Can we use protocol less URL while referencing jQuery from CDNs?
Yes we can. See code below:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
-
What is the advantage of using protocol less URL while referencing jQuery from CDNs?
Let's have an example. Your site is using HTTP protocol and you are moving from HTTP to HTTPS. Now you will have to make sure that correct protocol used for referencing jQuery library is HTTPS. "protocol-less" URL is the best way to reference third party content that’s available via both HTTP and HTTPS.
-
What is selector in jQuery?
jQuery selectors retrieve content from the web page so that it can be manipulated using other functions. jQuery selectors return an array of objects that match the selection criteria.
-
What is filter in jQuery?
jQuery filters operate on a selector to further refine the results array that the selector returns.
-
Can we use filters in jQuery without using of selectors?
Yes we can use filters in jQuery without using of selectors.
-
How many types of selectors are there?
There are many types of selectors. Please click here to know about each selectors.
-
How do you select element by ID selector in jQuery?
We need to use
#
(hash) symbol to select element by ID selector in jQuery.$("#test")
This selector selects element that has
test
as id attribute. -
How do you select element by class in jQuery?
We need to use
.
(dot) symbol to select element by class name in jQuery.$(".test")
This selector selects all the elements on which class
test
is applied. -
How can you select all elements in a page by jQuery?
You can use
*
(asterisk symbol) to select all page elements.$("*").css("border","1px solid red");
The code will select all page elements and will apply border on them.
-
What does $("div") will select?
This will select all the div elements on page.
-
What does $("div.parent") will select?
All the div element with parent class.
-
What are the fastest selectors in jQuery?
ID and element selectors are the fastest selectors in jQuery
-
What are the slow selectors in jQuery?
class selectors are the slow compare to ID and element.
-
How jQuery selectors are executed?
Selector execution is started from last. For Example:
$("div#test .abc");
jQuery will first find all the elements with class
.abc
and after that it will further refine selected elements by using first selector. It will reject all the other elements which are not indiv#test
. -
document.getElementByID('txtFirstName') is fast or $('#txtFirstName')?
As jQuery is written on top of JavaScript and it internally uses JavaScript only so JavaScript is always fast. In this scenario, jQuery method
$('#txtFirstName')
will internally makes a call todocument.getElementByID('txtName')
. -
What is the difference between $(this) and 'this' in jQuery?
this
and$(this)
both are same. When'this'
is wrapped in$()
then it becomes a jQuery object and you can use the features of jQuery. The only difference is the way they are used.$(document).ready(function(){ $('#divTest').click(function(){ alert($(this).text()); }); });
In below example, this is an object but since it is not wrapped in $(), we can't use jQuery method so we have used the native JavaScript to get the text of div element.
$(document).ready(function(){ $('#divTest').click(function(){ alert(this.innerText); }); });
-
How do you check if an element is empty?
There are 2 ways to check an element if it is empty:
Using ":empty" filter
Using "$.trim()" method$(document).ready(function(){ if ($('#div').is(':empty')){ //div is empty } });
$(document).ready(function(){ if($.trim($('#div').html())==') { //div is empty } });
-
What is the difference between eq() and get() methods in jQuery?
eq()
returns the element as a jQuery object that means that you can use jQuery functions on it.get()
return a DOM element. As it is a DOM element and it is not a jQuery-wrapped object So jQuery functions can't be used. -
What is the difference between $('div') and $('<div/>') in jQuery?
$('<div/>'):
It creates a new div element. This is not added to DOM tree unless you don't append it to any DOM element.$('div'):
This is a selector and selects all the div elements of page. -
What is the difference between parent() and parents() methods in jQuery?
The basic difference is the
parent()
function travels only one level in the DOM tree, whereparents()
function search through the whole DOM tree. -
How do you check if an element exists or not in jQuery?
We can check existence of an element by using
"length" propertysize()
function or length property
size() property$(document).ready(function(){ if ($('#div').length > 0){ //div exists } });
$(document).ready(function(){ if ($('#div').size()> 0){ //div exists } });
-
What is the difference between jquery.size() and jquery.length?
size()
method and.length
property both returns number of element in the object but the.length
property is preferred to use because it does not have the overhead of a function call. -
What is the use of $.each() function?
The
$.each()
function is used to iterate over any collection, whether it is an object or an array. -
What is the difference between find() and children() methods?
Both
find()
andchildren()
methods are used to filter the child of the matched elements. Butfind()
method is used to find all levels down the DOM tree butchildren()
find single level down the DOM tree. -
How do you implement animation functionality?
animate()
function is used to create custom animation for many CSS properties on page element. It changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect.Only numeric values can be animated (like
"margin:30px"
). String values cannot be animated (like"background-color:red"
).animate(params, duration, easing, callback)
- params: The css properties on the elements to animate
- duration: Specifies the speed of the animation. Default value is 400 milliseconds. Possible values: milliseconds, "slow“, "fast"
- easing: Specifies the speed of the element in different points of the animation. Default value is "swing". Possible values: "swing" - moves slower at the beginning/end, but faster in the middle "linear" - moves in a constant speed
- callback: The function to call when the animation is complete
Example of animation:$("btnClick").click(function(){ $("#divTest").animate({height:"200px"}); });
-
How do you disable jQuery animation?
"jQuery.fx.off"
property is used to disable animation. If it is true then all animation methods will immediately set elements to their final state when called, rather than displaying an effect. -
How do you stop the currently-running animation?
We can stop currently-running animation by using
stop()
method. -
What is finish method in jQuery?
The
.finish()
method stops all queued animations and places the element(s) in their final state. This method was introduced in jQuery 1.9. -
What is the difference between calling stop(true,true) and finish method?
The
.finish()
method is similar to.stop(true, true)
in that it clears the queue and the current animation jumps to its end value. It differs, however, in that .finish() also causes the CSS property of all queued animations to jump to their end values, as well. -
What are the methods used to provide effects?
These are some methods used to provide effects:
- show()
- hide()
- toggle()
- slideDown()
- slideUp()
- slideToggle
- fadeIn
- fadeOut
- fadeTo
-
What is the difference between .empty(), .remove() and .detach() methods in jQuery?
All these methods are used to remove elements from DOM. But there are some differences between them.
.empty():
This method removes all the child elements of the matched elements..remove():
This method removes the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are also removed..detach():
This method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time. -
What is difference between prop and attr?
attr()
get the value of an attribute for the first matched element from the set of matched elements.prop()
which was introduced in jQuery 1.6 gets the value of a property for the first matched element from the set of matched elements.Attributes carry additional information about an HTML element and come in
name="value"
pairs. Where Property is a representation of an attribute in the HTML DOM tree. Once the browser parse your HTML code, corresponding DOM node will be created which is an object thus having properties.attr()
gives you the value of element as it was defines in the html on page load. It is always recommended to useprop()
to get values of elements which is modified via javascript/jquery , as it gives you the original value of an element's current state. -
What is the use jQuery.data method?
jQuery.data()
methods is used to associate the data with the DOM nodes and the objects. It store arbitrary data associated with the specified element and/or return the value that was set.jQuery.data( document.body, "foo", 52 );
-
Is it possible to fetch value of multiple CSS properties in single statement?
Yes, it is possible by .css which was provided in version 1.9:
var testVar= $("#divTest").css([ "width", "height", "backgroundColor" ]); //now testVar variable will be and array like this: { width: "100px", height: "200px", backgroundColor: "#FF00FF" }
-
How to check if number is numeric while using jQuery 1.7+?
Using
"isNumeric()"
function which was introduced with jQuery 1.7. -
How to check data type of any variable in jQuery?
We can check data type of any variable by using
$.type(Object)
which returns the built-in JavaScript type for the object. -
Explain .bind() vs .live() vs .delegate() vs .on()
All these methods are used for attaching events to selectors or elements. But there are some differences between them.
.bind(): This is the easiest and quick method to bind events.
bind()
method only attach events to the current elements not future element. It will not bind events to elements added dynamically. It also has performance issues when dealing with a large selection..live(): This method overcomes the disadvantage of
bind()
. It works for dynamically added elements or future elements. But it also has performance issue on large pages. Chaining is also not properly supported using this method. Because of its poor performance, this method is deprecated as of jQuery 1.7 and you should stop using it..delegate(): The
.delegate()
method is same as.live()
method, but instead of attaching the selector/event information to the document, you can choose where it is anchored. It also supports chaining..on(): Since live was deprecated with 1.7, so new method was introduced named
".on()"
. This method has all features provided by.bind()
,.live()
and.delegate()
. -
How to create clone of any object using jQuery?
We can use
clone()
method of jQuery to create clone of any object.$(document).ready(function(){ $('#btnClone').click(function(){ $('#ddlCountry').clone().appendTo('body'); return false; }); });
-
Does events are also copied when you clone any element in jQuery?
Default implementation of the
clone()
method doesn't copy events unless you tell theclone()
method to copy the events. Theclone()
method takes a parameter, if you pass true then it will copy the events as well.$(document).ready(function(){ $('#btnClone').click(function(){ $('#ddlCountry').clone(true).appendTo('body'); return false; }); });
-
What is event.PreventDefault() function?
The
event.preventDefault()
method prevents the browser from executing the default action. For example, prevents a link from following the URL or prevents a submit button to submit the parent form. -
What is event.stopPropagation() function?
The
event.stopPropagation()
method stops the bubbling of an event to parent elements. For example, if there is a link with a click event attached inside of a DIV or FORM that also has a click attached, it will prevent the DIV or FORM click event from firing. -
What is the difference between event.PreventDefault and event.stopPropagation?
event.preventDefault():
Prevents the browser from executing the default action.event.stopPropagation():
Stops the bubbling of an event to parent elements -
What is the difference among event.PreventDefault, event.stopPropagation and "return false"?
event.preventDefault()
will prevent the default event from occurring,event.stopPropagation()
will prevent the event from bubbling up and return false will do both. -
What is the difference between event.stopPropagation and event.stopImmediatePropagation?
event.stopPropagation()
allows other handlers on the same element to be executed, whileevent.stopImmediatePropagation()
prevents every event from running.For example
$("div").click(function(e){ e.stopImmediatePropagation(); }); $("div").click(function(e){ // This function won't be executed $(this).css("background-color", "#f00"); });
If
event.stopPropagation
was used in previous example, then the next click event on div element which changes the css will fire, but in caseevent.stopImmediatePropagation()
, the next div click event will not fire. -
How do you attach a event to element which should be executed only once?
one()
method of jQuery is used to attach a event to element which should be executed only once. The handler attached by methodone()
executes only once.For Example:
$(document).ready(function() { $("#btnTest").one("click", function() { alert("This will be displayed only once."); }); });
In this example message will be shown only once by clicking on btnTest button
-
Can we use jQuery to make ajax request?
Yes, jQuery can be used to make ajax request.
-
What are various methods to make ajax request in jQuery?
There are multiple ways to make ajax request in jQuery:
load() :
Load a piece of html into a container DOM$.getJSON():
Load JSON with GET method.$.getScript():
Load a JavaScript file.$.get():
Use to make a GET call and play extensively with the response.$.post():
Use to make a POST call and don't want to load the response to some container DOM.$.ajax():
Use this to do something on XHR failures, or to specify ajax options (e.g. cache: true) on the fly.
-
What are the four parameters used for jQuery Ajax method?
These are the four parameters for jQuery ajax method:
url:
Specifies Url to send requesttype:
Specifies type of request (get or post)data:
Specifies data to be sent to servercache:
Whether the browser should cache the requested page or not
-
Is there any advantage of using $.ajax() for ajax call against $.get() or $.post()?
There is an advantage of using
$ajax()
for ajax call against$.get()
or$.post()
.$ajax()
provide you more functionalities like error callback for handling error in response but$.get()
and$.post()
do not provide this functionality. You will have to always trust the response from server and believe that it is going to be successful all time in case of$.get()
and$.post()
. -
What are deferred and promise object in jQuery?
These objects help in handling asynchronous functions like Ajax.
-
Can we execute/run multiple Ajax request simultaneously in jQuery? If yes, then how?
Yes, We can execute/run multiple ajax request simultaneously in jQuery using
.when()
method which provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events -
Can you call C# code-behind method using jQuery? If yes,then how?
Yes, We can call C# code-behind function via
$.ajax
. But for do that it is compulsory to mark the method as WebMethod. -
How to handle Ajax error globally?
ajaxError()
function is used to handle ajax error globally in jQuery.$( document ).ajaxError(function() { $( "span#log" ).text( "Triggered ajaxError handler." ); });
In the code above, if there will be any error in any ajax request then #log span will show error message
-
Can we include multiple version of jQuery?
Yes we can include multiple versions of jQuery in same page.
-
In what situation you would use multiple version of jQuery and how would you include them?
There may be a situation when we have a jQuery plugin in application which is dependent on older version of jQuery but for our own jQuery code, we want to use latest version of jQuery. So due to this dependency we will have to use multiple version of jQuery.
Here is an example to use multiple version of jQuery:
<script type='text/javascript' src='js/jquery_1.9.1.min.js'></script> <script type='text/javascript'> var $jq = jQuery.noConflict(); </script> <script type='text/javascript' src='js/jquery_1.7.2.min.js'></script>
By this way, for your own jQuery code use
"$jq"
, instead of"$"
as"$jq"
refers to jQuery 1.9.1, where"$"
refers to 1.7.2. -
Which is the latest version of jQuery library?
The latest version of jQuery library (at the time of writing this article) is 1.11.3 or 2.1.4.
-
Does jQuery 2.0 supports IE?
No. jQuery 2.0 has no support for IE 6, IE 7 and IE 8.
-
What are source maps in jQuery?
Source Map is mapping of minified version of jQuery against the un-minified version. Source map allows to debug minified version of jQuery library. Source map feature was release with jQuery 1.9.
-
How to use migrate jQuery plugin?
With release of 1.9 version of jQuery, many deprecated methods were discarded and they are no longer available. But there are many sites in production which are still using these deprecated features and it's not easy to replace them overnight. So jQuery team provided with jQuery Migrate plugin that makes code written prior to 1.9 work with it.
So to use old/deprecated features, you need to provide reference of jQuery Migrate Plugin.
-
How to write browser specific code using jQuery?
jQuery.browser
property is used to write browser specific code. This property contains flags for the useragent, read fromnavigator.userAgent
. This property was removed in jQuery 1.9. -
How can we check jQuery UI version?
The command
$.ui.version
returns jQuery UI version. -
What is jQuery plugin and what is the advantage of using plugin?
A plug-in is piece of code written in a standard JavaScript file . These files provide useful jQuery methods which can be used along with jQuery library methods. jQuery plugins are quite useful as its piece of code which is already written by someone and re-usable, which saves your development time.
-
What is jQuery UI?
jQuery UI provides a prebuilt set of functionality that gives your pages a polished, professional look and feel. It is an official plug-in with commonly used interface widgets, like slider controls, progress bars, accordions, etc.
-
What is the difference between jQuery and jQuery UI?
jQuery is the core library. jQueryUI is built on top of it. If you use jQueryUI, you must also include jQuery.
-
What is jQuery Connect?
jQuery Connect is a jquery plugin which enables us to connect a function to another function. It is like assigning a handler for another function. This situation happens when you are using any javascript plugins and you want to execute some function when ever some function is executed from the plugin. This we can solve using jquery connect function.
-
What is the use of $.disconnect() function?
$.disconnect()
function is used to disconnect a function to another function. It is opposite of$.connect()
. -
What is statement chaining in jQuery?
Chaining is one of the most powerful feature of jQuery. Chaining provides the ability to chain multiple functions together to perform several operations in one line of code. It makes your code short and easy to manage. The chain starts from left to right. So left most will be called first and so on.
Syntax$(selector).fn1().fn2().fn3();
$(document).ready(function(){ $('#divTest').addClass('test'); $('#divTest').css('color', 'blue'); $('#divTest').fadeIn('slow'); });
Using chaining, you can write above jQuery code like this:
$(document).ready(function(){ $('#divTest').addClass('test').css('color', 'blue').fadeIn('slow'); });
-
How does caching helps and how to use caching in jQuery?
Caching helps to increase performance and it can also be used in jQuery. If you are using an element in jQuery more than one time then you should cache that element.
For example:
$("#divTest").css("color", "red"); $("#divTest").html("Some Text Here!"); //Some more code for #divTest
In jQuery code given above, we are using
#divTest
multiple time. Whenever it will be used like this, jQuery will have to traverse through DOM to get that element. We can avoid this extra traversing by saving this div in a variable:var $divTest = $("#divTest"); $divTest.css("color", "red"); $divTest.html("Some Text Here!"); //Some more code for #divTest
Now jQuery will not traverse again to find
#divTest
. We can user variable#divTest
. In jQuery caching means saving jQuery selector in a variable and use that variable reference whenever required. -
You get "jquery is not defined" or "$ is not defined" error. What could be the reason?
There may be many reasons for this:
- You have forgot to include the reference of jQuery library and trying to access jQuery.
- You have include the reference of the jQuery file, but name or path of referenced jQuery file is not correct.
- You have include the reference of the jQuery file, but it is after your jQuery code.
- The order of the scripts is not correct. For example, if you are using any jQuery plugin and you have placed the reference of the plugin js before the jQuery library then you will face this error.
-
How can we encode or decode url in jQuery?
You need to use follwing methods for encoding and decoding of url in jQuery:
Encode: encodeURIComponent(url)
Decode: decodeURIComponent(url)
You need to pass the complete url with parameterized value in the function. These functions will return you encoded/decoded url as a result.
-
How to disable browser back button through jQuery?
You can use following code to disable browser back button:
window.history.forword(1); //or window.history.forword(-1);
-
How to disable mouse right click using jQuery?
$(document).ready(function() { $(this).bind("contextmenu"),function(e) { e.preventDefault(); }); });
-
How to disable cut, copy paste in jQuery?
$(document).ready(function() { $("#txtTest").bind("copy paste cut"),function(e) { e.preventDefault(); }); });
By using code given above cut, copy and paste will be disabled on #txtTest textbox.