Here you find interview questions related to developing hybrid apps using phonegap.
Some questions will be repeated. some questions cannot understand leave them.
Building applications for each device--iPhone, Android, Windows Mobile and more--requires different frameworks and languages.
One day, the big players in mobile may decide to work together and unify third-party app development processes.
Until then, PhoneGap will use standards-based web technologies to bridge web applications and mobile devices. Plus, because PhoneGap apps are standards compliant, they're future-proofed to work with browsers as they evolve.
PhoneGap is an open source implementation of open standards. That means developers and companies can use PhoneGap for mobile applications that are free, commercial, open source, or any combination of these.
Property lists are a way of structuring arbitrary data and accessing it at run-time. An information property list is a specialized type of property list that contains configuration data for a bundle. The keys and values in the file describe the various behaviors and configuration options you want applied to your bundle. Xcode typically creates an information property list file for any bundle-based projects automatically and configures an initial set of keys and values with appropriate default values. You can edit the file to add any keys and values that are appropriate for your project or change the default values of existing keys.
For further details click here.
4. What is the difference between ChildBrowser and InAppBrowser in PhoneGap ?
As the name suggests, Child Browser Plugin is a plugin and can be integrated in any phonegap application.
Whereas, InAppBrowser is a phonegap API that provides the ability to spawn a browser instance from a Cordova(2.3.0) application. The API is based on standard browser capability. In a nutshell, this has the same functionality as the ChildBrowser, and has events support as well.
Example usage:
var ref = window.open('http://google.com', '_blank');
ref.addEventListener('loadstart', function(event) { alert(event.type + ' - ' + event.url); } );
ref.addEventListener('loadstop', function(event) { alert(event.type + ' - ' + event.url); } );
ref.addEventListener('exit', function(event) { alert(event.type); } );
// also, you can do ref.removeEventListener('loadstart', myfunc) .. etc
5. What are CDNs in jQuery? Why do we use it?
CDNs(Content Delivery Networks) can offer a performance benefit by hosting jQuery on servers spread across the globe.
There are three CDNs available that host the jQuery library free of charge:
Q3. How JavaScript and jQuery are different?
Ans: JavaScript is a language While jQuery is a library built in the JavaScript language that helps to use the JavaScript language.
Q4. Is jQuery replacement of Java Script?
Ans: No. jQuery is not a replacement of JavaScript. jQuery is a different library which is written on top of JavaScript. jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML.
Q5. Is jQuery a library for client scripting or server scripting?
Ans. Client side scripting.
Q6. Does jQuery follow W3C recommendations?
Ans: No.
Q7. What is the basic need to start with jQuery?
Ans: To start with jQuery, one need to make reference of it's library. The latest version of jQuery can be downloaded from jQuery.com.
Q8. Which is the starting point of code execution in jQuery?
Ans: The starting point of jQuery code execution is $(document).ready() function which is executed when DOM is loaded.
Q9. What does dollar sign ($) means in jQuery?
Ans: Dollar Sign is nothing but it's an alias for JQuery. Take a look at below jQuery code.
Q15. What is the difference between .js and .min.js?
Ans: jQuery library comes in 2 different versions Production and Deployment. The deployment version is also known as minified version. So .min.js is basically the minified version of jQuery library 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.
Q16. Why there are two different version of jQuery library?
Ans: jQuery library comes in 2 different versions.
Q19. How to load jQuery from CDN?
Ans: Below is the code to load jQuery from all 3 CDNs.
Code to load jQuery Framework from Google CDN
Q22. How do you select element by ID in jQuery?
Ans: To select element use ID selector. We need to prefix the id with "#" (hash symbol). For example, to select element with ID "txtName", then syntax would be,
Q44. How to create clone of any object using jQuery?
Ans: jQuery provides clone() method which performs a deep copy of the set of matched elements, meaning that it copies the matched elements as well as all of their descendant elements and text nodes.
Q60. How to write browser specific code using jQuery?
Ans: Using jQuery.browser property, we can write browser specific code. This property contains flags for the useragent, read from navigator.userAgent. This property was removed in jQuery 1.9.
Q61. Can we use jQuery to make ajax request?
Ans: Yes. jQuery can be used for making ajax request.
Q62. What are various methods to make ajax request in jQuery?
Ans: Using below jQuery methods, you can make ajax calls.
What is Initial release of JQuery Mobile?
October 16, 2010
Question: What is Latest version of jQuery Mobile?
Version: 1.4.5
Dated: October 31, 2014
Question: In which language, jQuery mobile is written?
JavaScript
Question: Where it is used?
It is "Mobile application framework" which is used for creating mobile web applications.
Question: What is offical website of jQuery Mobile?
http://jquerymobile.com/
Question: What are Features of jQuery Mobile?
Question: Why Use jQuery Mobile?
1. Write Less, Do more
2. Its works on Android, Blackberry, iOS and Iphone
3. Its optimized
Question: Describe few HTML tags used in jQuery Mobile?
data-role="page": Page displayed in the browser.
data-role="header": Creates a toolbar at the top of the page.
data-role="main": Content of the page, like text, images, buttons and forms etc.
"ui-content": Adds extra padding and margin inside the page content
data-role="footer": creates a toolbar at the bottom of the page
Question: How to Add Back Button?
Question: What is jQuery Mobile Themeing?
jQuery Mobile provides a powerful theming that allows developers to customize color schemes & CSS aspects of UI features.
(7) What is the difference between windows.onload and onDocumentReady?
Some questions will be repeated. some questions cannot understand leave them.
PhoneGap
1) Explain what PhoneGap is and why to use it?
PhoneGap is an open source framework, which enables you to develop applications for mobile devices by using web technologies like CSS3, JavaScript and HTML5 instead of using Java for Android, C# for windows phone devices and Objective C or Swift for iOS. It uses the native project format for each platform.
2) List out some of the PhoneGap API?
Some of the PhoneGap API are
· Accelerometer
· Camera
· Capture
· Compass
· Connection
· Contacts
· Device
· Geo-location and so on
3) Explain what do you need to develop in PhoneGap?
For,
· IOS: Xcode, iOS SDK
· Android: Android SDK, ADT plugin
· BlackBerry: Sun SDK, Apache ant and BlackBerry Webworks SDK
· Symbian: SDK
4) Mention what is the difference between PhoneGap and PhoneGap Build?
· PhoneGap: It is a framework for mobile application development, built upon the open source Apache Cordova project. It permits you to write an app once with CSS, JavaScript, HTML and then deploys it to a broad range of mobile devices without losing the features of a native app.
· PhoneGap Build: It is a cloud-based service built on top of the PhoneGap framework.
5) List out some of the PhoneGap events?
Some of the PhoneGap events include
· Pause
· Resume
· Deviceready
· Offline
· Endcallbutton
· Volumedownbutton and so on
6) Mention the difference between AIR and PhoneGap?
The most fundamental differences between AIR and PhoneGap is that you build AIR applications using tools rooted in the Flash Platform, and you can develop PhoneGap application using HTML, CSS and JavaScript. AIR applications use the AIR runtime, it enables you to have a single code base, with the exact similar expected behavior through all supported platforms. PhoneGap applications execute inside of the native web browser component for each supported platform. For separate platform, PhoneGap may behave differently.
7) Explain how do you architect PhoneGap applications?
PhoneGap applications can be architect, in the same way, like other mobile web services. The main difference is that the initial HTML assets are available locally, instead of a remote server. The PhoneGap application loads the initial HTML which can request resources from a server or from the local environment. PhoneGap also supports the single page web experienced model.
8) What does PhoneGap plugin consist of? What are the files required to create your own PhoneGap plugin for IOS?
PhoneGap plugin contains two files
· JavaScript file that defines the function for accessing the native hooks
· Implementation files written in the native language to co-ordinate with native phone features
To create your own PhoneGap plugins, you have to
· Make a new directory in your ${PROJECT_DIR}/plugins directory
· Make a JavaScript file within that new directory
· Make a new Objective-C class that extends the PhoneGap command class and also in the new directory
9) List out what features are available in PhoneGap cameraoptions?
PhoneGap cameraoptions available are
· Quality: It tells the quality of saved image that range from [0,100]
· Destination Type: Choose the format of the return value. Defined in navigator.camera.DestinationType
· Source Type: Set the source of the picture. Defined in navigator.camera
· AllowEdit: Before selection of image, it allows simple editing of image
· Encoding Type: It determines the encoding type of the returned image
· TargetWidth: It determines how you can set image width
· TargetHeight: It tells how you can set image height
· Media Type: Here you can set the media type to select from
10) Explain how you can upgrade PhoneGap?
To upgrade PhoneGap in Mac and Linux
· $ sudo npm install –g phonegap
For Windows:
· C:\> npm install –g phonegap
11) Mention what are the iOS quirks for a compass heading object?
For a compass heading object the iOS quirks are
· trueHeading is returned only when location services are executing through geolocation.watchlocation()
· For iOS>4 devices, if the mobile device is revolved or rotated and the app supports that orientation, the heading value will be reported back with respect to the current orientation
12) Explain what is media.seekTo and media.getDuration function in OpenGap media API?
· seekTo in OpenGap Media API is a function that updates the latest position of the underlying audio file of a Media Object
· getDuration is a function that returns the duration of the audio file in seconds. It will return the value -1, if the duration is unknown
13) Explain what are the limitation of PhoneGap?
As the front-end uses JavaScript it does have some limitation
Data processing: Compare to JavaScript native language is much faster
·Background processing: Large number of application depends on background thread while PhoneGap API are built using JavaScript which does not support multi-threaded and hence does not support back ground processing
· Advanced graphics: Apps that use advanced graphics can be accessed explicitly by third party libraries, which can be best done natively
· Complex business logic: Number of complex business app can be accessed better with a native code
· Access advanced native functionality: Number of native API’s are not supported by PhoneGap’s API
14) Mention what are the storage option does PhoneGap can access?
·Background processing: Large number of application depends on background thread while PhoneGap API are built using JavaScript which does not support multi-threaded and hence does not support back ground processing
· Advanced graphics: Apps that use advanced graphics can be accessed explicitly by third party libraries, which can be best done natively
· Complex business logic: Number of complex business app can be accessed better with a native code
· Access advanced native functionality: Number of native API’s are not supported by PhoneGap’s API
14) Mention what are the storage option does PhoneGap can access?
· Memory-store.js (MemoryStore)
· Is-store.js (LocalStorageStore)
· Websql-store.js (WebSqlStore)
1.What is PhoneGap ?
PhoneGap is an open source solution for building cross-platform mobile apps with standards-based Web technologies like HTML, JavaScript, CSS.
It is a wrapper used for native packaging of mobile web application which is used to build cross platform mobile Application.
2.Who Developed PhoneGap ?
It is developed by Nitobi, a company based in Vancouver, Canada.
Nitobi was acquired by Adobe Corporation on the year of 2011.
After the acquisition Adobe released PhoneGap technology as open source under the name Apache Cordova.
3.PhoneGap architecture.
PhoneGap has a plugin-based architecture. Each device-specific feature is a plugin, which consists of javascript and native sides.
Js side should be as cross-platform as possible, whereas native side can be implemented only once, for 1 device. Nevertheless built-in plugins are developed for all of the most popular platforms, so no need to reinvent the wheel.
This architecture, together with open source code, not only allows a developer to fix their bugs, but also allows them to tweak their plugins for as per requirements. Also, a developer can build his own plugin, and support any platform of his choice.
4.Why should mobile developers consider phonegap?
Mobile developers use PhoneGap because it allows them to have a common codebase for all their application code. It doesn’t force developers to reinvent the wheel every time they move from platform to platform.
5.How does phoneGap simplifies mobile development?
Building applications for each device--iPhone, Android, Windows Mobile and more--requires different frameworks and languages.
One day, the big players in mobile may decide to work together and unify third-party app development processes.
Until then, PhoneGap will use standards-based web technologies to bridge web applications and mobile devices. Plus, because PhoneGap apps are standards compliant, they're future-proofed to work with browsers as they evolve.
PhoneGap is an open source implementation of open standards. That means developers and companies can use PhoneGap for mobile applications that are free, commercial, open source, or any combination of these.
6.what are the platforms that PhoneGap supports ?
The platforms phone gap supports are
· iphone/iphone 3G and Higher
· Blackberry os 5.x and Newer
· Android
· Web OS
· Tizen
· Windows Phone 7
· Symbian
· Bada
7. PhoneGap Features
It allows you to package your mobile web application code and resources into a binary app and ready to distribute to Apple, Android, Palm, Symbian, and BlackBerry devices.
It is not only the purpose of PhoneGap to distribute the web application to application store.
It is also providing the feature to access the device hardware from web application.
It allows you to package your mobile web application code and resources into a binary app and ready to distribute to Apple, Android, Palm, Symbian, and BlackBerry devices.
It is not only the purpose of PhoneGap to distribute the web application to application store.
It is also providing the feature to access the device hardware from web application.
8. Advantages of PhoneGap
One codebase can be maintained for multiple platforms
Reuse existing web developer skills
Faster development
Based on open standards
9. What is PhoneGap Cordova
Mobile market is huge with bunch of opportunities. At the same time it is really painful experience for the developers to make an application reach to the wider audience.
There are multiple platforms like android, iPhone, Blackberry, windows comes with lot different capabilities. Every platform uses different programming language syntax and different distribution process.
As the programming platforms are different, developing an application requires putting the separate development effort for different platforms.
10. What is the difference between PhoneGap and Cordova?
PhoneGap was donated to the Apache Software Foundation (ASF) under the name Apache Cordova. Through the ASF, future PhoneGap development will ensure open stewardship of the project. It will remain free and open source under the Apache License, Version 2.0.
PhoneGap is an open source distribution of Cordova. Think about Cordova’s relationship to PhoneGap like WebKit’s relationship to Safari or Chrome.
11. What is PhoneGap Build, and how is it different from PhoneGap framework?
PhoneGap is a mobile application development framework, based upon the open source Apache Cordova project.It allows you to write an app once with HTML, CSS and JavaScript, and then deploy it to a wide range of mobile devices without losing the features of a native app.
PhoneGap Build is a cloud-based service built on top of the PhoneGap framework.
It allows you to easily build those same mobile apps in the cloud. Learn more about PhoneGap Build and try it out for free!
12. What is a hybrid app?
A hybrid application is one that has features of both a web application and a native application. Certain features, such as Image Capture, NFC or Android OpenAccessory, may be implemented natively since there is currently no way to do this in JavaScript. But the application logic and the UI are implemented using web technologies to allow for a consistent and unique user experience across devices.
13. what are the PhoneGap events
The phone gap events are listed below
· deviceready
· pause
· resume
· online
· offline
· backbutton
· batterycritical
· batterylow
· batterystatus
· menubutton
· searchbutton
· startcallbutton
· endcallbutton
· volumedownbutton
· volumeupbutton
14. Can you use PHP/ASP/JSF/Java/.NET with PhoneGap?
A PhoneGap application may only use HTML, CSS, and JavaScript. However, you can make use of network protocols (XmlHTTPRequest, Web Sockets, etc) to easily communicate with backend services written in any language. This allows your PhoneGap app to remotely access existing business processes while the device is connected to the Internet.
15. How much does PhoneGap cost?
PhoneGap is an open source implementation of open standards and FREE. That means developers and companies can use PhoneGap for mobile applications that are free, commercial, open source, or any combination of these.
1. What is PhoneGap and why ?
PhoneGap is a mobile application framework that allows developers to use HTML, JavaScript and CSS to create mobile apps that are present as first-class applications on the phone. That means the mobile apps have their own icons and operate similarly to native applications without a browser frame around them.
They have access to a set of native functions to further make them work like native apps.
Mobile developers use PhoneGap because it allows them to have a common codebase for all their application code. It doesn’t force developers to write code from scratch every time they move from platform to platform.
2. PhoneGap architecture.
PhoneGap has a plugin-based architecture. Each device-specific feature is a plugin, which consists of javascript and native sides. Js side should be as cross-platform as possible, whereas native side can be implemented only once, for 1 device. Nevertheless built-in plugins are developed for all of the most popular platforms, so no need to reinvent the wheel.
This architecture, together with open source code, not only allows a developer to fix their bugs, but also allows them to tweak their plugins for as per requirements. Also, a developer can build his own plugin, and support any platform of his choice.
3. What is a Plist file in iOS development ?
Yes, this is not related to phonegap, but interviewer expects the answer!
PhoneGap is a mobile application framework that allows developers to use HTML, JavaScript and CSS to create mobile apps that are present as first-class applications on the phone. That means the mobile apps have their own icons and operate similarly to native applications without a browser frame around them.
They have access to a set of native functions to further make them work like native apps.
Mobile developers use PhoneGap because it allows them to have a common codebase for all their application code. It doesn’t force developers to write code from scratch every time they move from platform to platform.
2. PhoneGap architecture.
PhoneGap has a plugin-based architecture. Each device-specific feature is a plugin, which consists of javascript and native sides. Js side should be as cross-platform as possible, whereas native side can be implemented only once, for 1 device. Nevertheless built-in plugins are developed for all of the most popular platforms, so no need to reinvent the wheel.
This architecture, together with open source code, not only allows a developer to fix their bugs, but also allows them to tweak their plugins for as per requirements. Also, a developer can build his own plugin, and support any platform of his choice.
3. What is a Plist file in iOS development ?
Yes, this is not related to phonegap, but interviewer expects the answer!
Property lists are a way of structuring arbitrary data and accessing it at run-time. An information property list is a specialized type of property list that contains configuration data for a bundle. The keys and values in the file describe the various behaviors and configuration options you want applied to your bundle. Xcode typically creates an information property list file for any bundle-based projects automatically and configures an initial set of keys and values with appropriate default values. You can edit the file to add any keys and values that are appropriate for your project or change the default values of existing keys.
For further details click here.
4. What is the difference between ChildBrowser and InAppBrowser in PhoneGap ?
As the name suggests, Child Browser Plugin is a plugin and can be integrated in any phonegap application.
Whereas, InAppBrowser is a phonegap API that provides the ability to spawn a browser instance from a Cordova(2.3.0) application. The API is based on standard browser capability. In a nutshell, this has the same functionality as the ChildBrowser, and has events support as well.
Example usage:
var ref = window.open('http://google.com', '_blank');
ref.addEventListener('loadstart', function(event) { alert(event.type + ' - ' + event.url); } );
ref.addEventListener('loadstop', function(event) { alert(event.type + ' - ' + event.url); } );
ref.addEventListener('exit', function(event) { alert(event.type); } );
// also, you can do ref.removeEventListener('loadstart', myfunc) .. etc
5. What are CDNs in jQuery? Why do we use it?
CDNs(Content Delivery Networks) can offer a performance benefit by hosting jQuery on servers spread across the globe.
There are three CDNs available that host the jQuery library free of charge:
· Google’s Libraries API CDN (a.k.a. Google Ajax API CDN)
· Media Temple’s ProCDN (the official “jQuery CDN”)
Using jQuery's CDN provided by MediaTemple
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
There are several benefits to using CDNs:
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
There are several benefits to using CDNs:
· The file will normally load faster than it would if self hosted.
· Odds are better that the site visitor will have a cached copy of the file since other sites will also be linking to the same file.
· It saves the site owner some bandwidth since the file is externally hosted.
6. Name PhoneGap events
· deviceready
· pause
· resume
· online
· offline
· backbutton
· batterycritical
· batterylow
· batterystatus
· menubutton
· searchbutton
· startcallbutton
· endcallbutton
· volumedownbutton
· volumeupbutton
1. What is PhoneGap and why should mobile developers consider using phonegap?
2. PhoneGap is a mobile application framework that allows developers to use HTML, JavaScript and CSS to create mobile apps that are present as first-class applications on the phone. That means the mobile apps have their own icons and operate similarly to native applications without a browser frame around them.
They are distributed via the application stores, such as the Android Market and the Apple App Store, and they have access to a set of native functions to further make them work like native apps.
Mobile developers use PhoneGap because it allows them to have a common codebase for all their application code. It doesn’t force developers to reinvent the wheel every time they move from platform to platform.
2. Are there downsides to using PhoneGap? or Limitations of Phonegap
You are subject to the limitations of the browser and the JavaScript engine that comes with your device. On Android 2.3, this isn’t too bad. Earlier versions of Android don’t support certain features, and many of them use older JavaScript interpreters, which can impact an application. Also, there are certain things that are better implemented in native code, like cryptography or 3-D graphics. Most apps don’t use features like this — they simply display information, which the web does well.
3. What’s the best way for PhoneGap developers to handle device-specific needs?
It depends on the feature set. Most mobile applications don’t need many device-specific features beyond the user interface, but there are numerous plugins that can help with this approach. The best approach is to decide what features you need and to use only those features. There are many applications that have permissions turned on that they don’t need. For example, a simple ebook doesn’t need access to your phone state, GPS or contacts.
4. What is a hybrid app?
A hybrid application is one that has features of both a web application and a native application. Certain features, such as Image Capture, NFC or Android OpenAccessory, may be implemented natively since there is currently no way to do this in JavaScript. But the application logic and the UI are implemented using web technologies to allow for a consistent and unique user experience across devices.
5. How phonegap simplifies mobile development?
Mobile development is a mess. Building applications for each device--iPhone, Android, Windows Mobile and more--requires different frameworks and languages. One day, the big players in mobile may decide to work together and unify third-party app development processes. Until then, PhoneGap will use standards-based web technologies to bridge web applications and mobile devices. Plus, because PhoneGap apps are standards compliant, they're future-proofed to work with browsers as they evolve.
PhoneGap is an open source implementation of open standards. That means developers and companies can use PhoneGap for mobile applications that are free, commercial, open source, or any combination of these.
HTML5
(1) What is the use of Canvas Element in HTML5?
HTML5 Canvas element can be used to draw graphics images on a web page by using javascript.
(2) Can you give an example of Canvas element how it can be used?
<canvas id=“DGTCanvas” width=“500″ height=“400″>
</canvas>
<script type=“text/javascript”>
var DGTCanvas=document.getElementById(“DGTCanvas”);
var DGTText=DGTCanvas.getContext(“2d”);
DGTText.fillStyle=“#82345c”;
DGTText.fillRect(0,0,150,75);
</script>
<canvas id=“DGTCanvas” width=“500″ height=“400″>
</canvas>
<script type=“text/javascript”>
var DGTCanvas=document.getElementById(“DGTCanvas”);
var DGTText=DGTCanvas.getContext(“2d”);
DGTText.fillStyle=“#82345c”;
DGTText.fillRect(0,0,150,75);
</script>
This book is far better than any other learning material. It has very basic information that includes both HTML5 and CSS3 with sample code and comprehensive examples.
(3) What is the purpose of HTML5 versus XHTML?
HTML5 is the next version of HTML 4.01, XHTML 1.0 and DOM Level 2 HTML. It aims to reduce the need for proprietary plug-in-based rich internet application (RIA) technologies such as Adobe Flash, Microsoft Silverlight, Apache Pivot, and Sun JavaFX. Instead of using those plugins, it enables browser to serve elements such as video and audio without any additional requirements on the client machine.
Related article on DGlobalTech.com
(4) What is the difference between HTML and HTML5 ?
HTML5 is nothing more then upgraded version of HTML where in HTML5 supports the innovative features such as Video, Audio/mp3, date select function , placeholder , Canvas, 2D/3D Graphics, Local SQL Database added so that no need to do external plugin like Flash player or other library elemenents.
(5) WHAT are some other advantages of HTML5?
a) Cleaner markup than earlier versions of HTML
b) Additional semantics of new elements like <header>, <nav>, and <time>
c) New form input types and attributes that will (and in Opera’s case, do) take the hassle out of scripting forms.
b) Additional semantics of new elements like <header>, <nav>, and <time>
c) New form input types and attributes that will (and in Opera’s case, do) take the hassle out of scripting forms.
(6) What is the <!DOCTYPE>? Is it mandatory to use in HTML5?
The <!DOCTYPE> is an instruction to the web browser about what version of HTML the page is written in. The <!DOCTYPE> tag does not have an end tag. It is not case sensitive.
The <!DOCTYPE> declaration must be the very first thing in HTML5 document, before the <html> tag. As In HTML 4.01, all <! DOCTYPE > declarations require a reference to a Document Type Definition (DTD), because HTML 4.01 was based on Standard Generalized Markup Language (SGML). WHERE AS HTML5 is not based on SGML, and therefore does not require a reference to a Document Type Definition (DTD).
(7) What are the New Media Elements in HTML5?
New Media Elements in HTML5 are :
TAG
|
DESCRIPTION
|
<audio>
|
For multimedia content, sounds, music or other audio streams
|
<video>
|
For video content, such as a movie clip or other video streams
|
<source>
|
For media resources for media elements, defined inside video or audio
elements |
<embed>
|
For embedded content, such as a plug-in
|
<track>
|
For text tracks used in mediaplayers
|
(8) What is the major improvement with HTML5 in reference to Flash?
Flash is not supported by major mobile devices such as iPad, iPhone and universal android applications. Those mobile devices have lack of support for installing flash plugins. HTML5 is supported by all the devices, apps and browser including Apple and Android products. Compared to Flash, HTML5 is very secured and protected. That eliminates major concerns that we have seen with Flash.
(10) What is the sessionStorage Object in html5 ? How you can create and access that?
The HTML5 sessionStorage object stores the data for one session. The data is deleted when the user closes the browser window. We can create and access a sessionStorage, created “name” as session
<script type=“text/javascript”>
sessionStorage.name=“DGTECH”;
document.write(sessionStorage.name);
</script>
sessionStorage.name=“DGTECH”;
document.write(sessionStorage.name);
</script>
JqueryMobile
Q1. What is jQuery?
Ans: jQuery is fast, lightweight and feature-rich client side JavaScript Library/Framework which helps in to traverse HTML DOM, make animations, add Ajax interaction, manipulate the page content, change the style and provide cool UI effect. It is one of the most popular client side library and as per a survey it runs on every second website.
Q2. Why do we use jQuery?
Ans: Due to following advantages.
Ans: jQuery is fast, lightweight and feature-rich client side JavaScript Library/Framework which helps in to traverse HTML DOM, make animations, add Ajax interaction, manipulate the page content, change the style and provide cool UI effect. It is one of the most popular client side library and as per a survey it runs on every second website.
Q2. Why do we use jQuery?
Ans: Due to following advantages.
· Easy to use and learn.
· Easily expandable.
· Cross-browser support (IE 6.0+, FF 1.5+, Safari 2.0+, Opera 9.0+)
· Easy to use for DOM manipulation and traversal.
· Large pool of built in methods.
· AJAX Capabilities.
· Methods for changing or applying CSS, creating animations.
· Event detection and handling.
· Tons of plug-ins for all kind of needs.
Q3. How JavaScript and jQuery are different?
Ans: JavaScript is a language While jQuery is a library built in the JavaScript language that helps to use the JavaScript language.
Q4. Is jQuery replacement of Java Script?
Ans: No. jQuery is not a replacement of JavaScript. jQuery is a different library which is written on top of JavaScript. jQuery is a lightweight JavaScript library that emphasizes interaction between JavaScript and HTML.
Q5. Is jQuery a library for client scripting or server scripting?
Ans. Client side scripting.
Q6. Does jQuery follow W3C recommendations?
Ans: No.
Q7. What is the basic need to start with jQuery?
Ans: To start with jQuery, one need to make reference of it's library. The latest version of jQuery can be downloaded from jQuery.com.
Q8. Which is the starting point of code execution in jQuery?
Ans: The starting point of jQuery code execution is $(document).ready() function which is executed when DOM is loaded.
Q9. What does dollar sign ($) means in jQuery?
Ans: Dollar Sign is nothing but it's an alias for JQuery. Take a look at below jQuery code.
1
|
$(document).ready(function(){
|
2
|
});
|
Over here $ sign can be replaced with "jQuery" keyword.
1
|
jQuery(document).ready(function(){
|
2
|
});
|
Q10. Can we have multiple document.ready() function on the same page?
Ans: YES. We can have any number of document.ready() function on the same page.
Q11. Can we use our own specific character in the place of $ sign in jQuery?
Ans: Yes. It is possible using jQuery.noConflict().
Q12. Is it possible to use other client side libraries like MooTools, Prototype along with jQuery?
Ans: Yes.
Q13. What is jQuery.noConflict?
Ans: As other client side libraries like MooTools, Prototype can be used 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 introduced jQuery.noConflict().
Ans: YES. We can have any number of document.ready() function on the same page.
Q11. Can we use our own specific character in the place of $ sign in jQuery?
Ans: Yes. It is possible using jQuery.noConflict().
Q12. Is it possible to use other client side libraries like MooTools, Prototype along with jQuery?
Ans: Yes.
Q13. What is jQuery.noConflict?
Ans: As other client side libraries like MooTools, Prototype can be used 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 introduced jQuery.noConflict().
1
|
jQuery.noConflict();
|
2
|
// Use jQuery via jQuery(...)
|
3
|
jQuery(document).ready(function(){
|
4
|
jQuery("div").hide();
|
5
|
});
|
You can also use your own specific character in the place of $ sign in jQuery.
1
|
var $j = jQuery.noConflict();
|
2
|
// Use jQuery via jQuery(...)
|
3
|
$j(document).ready(function(){
|
4
|
$j("div").hide();
|
5
|
});
|
Q14. Is there any difference between body onload() and document.ready() function?
Ans: document.ready() function is different from body onload() function for 2 reasons.
Ans: document.ready() function is different from body onload() function for 2 reasons.
· We can have more than one document.ready() function in a page where we can have only one body onload function.
· document.ready() function is called as soon as DOM is loaded where body.onload() function is called when everything gets loaded on the page that includes DOM, images and all associated resources of the page.
Q15. What is the difference between .js and .min.js?
Ans: jQuery library comes in 2 different versions Production and Deployment. The deployment version is also known as minified version. So .min.js is basically the minified version of jQuery library 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.
Q16. Why there are two different version of jQuery library?
Ans: jQuery library comes in 2 different versions.
· Production
· Deployment
The production version is quite useful at development time as jQuery is open source and if you want to change something then you can make those changes in production 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.
Q17. What is a CDN?
Ans: A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance.
Q18. Which are the popular jQuery CDN? and what is the advantage of using CDN?
Ans: There are 3 popular jQuery CDNs.
Q17. What is a CDN?
Ans: A content delivery network or content distribution network (CDN) is a large distributed system of servers deployed in multiple data centers across the Internet. The goal of a CDN is to serve content to end-users with high availability and high performance.
Q18. Which are the popular jQuery CDN? and what is the advantage of using CDN?
Ans: There are 3 popular jQuery CDNs.
· 1. Google.
· 2. Microsoft
· 3. jQuery.
Advantage of using CDN.
· It reduces the load from your server.
· It saves bandwidth. jQuery framework will load faster from these CDN.
· The most important benefit is it will be cached, if the user has visited any site which is using jQuery framework from any of these CDN
Q19. How to load jQuery from CDN?
Ans: Below is the code to load jQuery from all 3 CDNs.
Code to load jQuery Framework from Google CDN
1
|
<script type="text/javascript"
|
2
|
3
|
</script>
|
Code to load jQuery Framework from Microsoft CDN
1
|
<script type="text/javascript"
|
2
|
3
|
</script>
|
Code to load jQuery Framework from jQuery Site(EdgeCast CDN)
1
|
<script type="text/javascript"
|
2
|
3
|
</script>
|
Q20. How to load jQuery locally when CDN fails?
Ans: It is a good approach to always use CDN but sometimes what if the CDN is down (rare possibility though) but you never know in this world as anything can happen.
Below given jQuery code checks whether jQuery is loaded from Google CDN or not, if not then it references the jQuery.js file from your folder.
Ans: It is a good approach to always use CDN but sometimes what if the CDN is down (rare possibility though) but you never know in this world as anything can happen.
Below given jQuery code checks whether jQuery is loaded from Google CDN or not, if not then it references the jQuery.js file from your folder.
1
|
<script type="text/javascript"src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
2
|
<script type="text/javascript">
|
3
|
if (typeof jQuery == 'undefined')
|
4
|
{
|
5
|
document.write(unescape("%3Cscript src='Scripts/jquery.1.9.1.min.js' type='text/javascript'%3E%3C/script%3E"));
|
6
|
}
|
7
|
</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.
Q21. What are selectors in jQuery and how many types of selectors are there?
Ans: To work with an element on the web page, first we need to find them. To find the html element in jQuery we use selectors. There are many types of selectors but basic selectors are:
Q21. What are selectors in jQuery and how many types of selectors are there?
Ans: To work with an element on the web page, first we need to find them. To find the html element in jQuery we use selectors. There are many types of selectors but basic selectors are:
· Name: Selects all elements which match with the given element Name.
· #ID: Selects a single element which matches with the given ID
· .Class: Selects all elements which match with the given Class.
· Universal (*): Selects all elements available in a DOM.
· Multiple Elements E, F, G: Selects the combined results of all the specified selectors E, F or G.
· Attribute Selector: Select elements based on its attribute value.
Q22. How do you select element by ID in jQuery?
Ans: To select element use ID selector. We need to prefix the id with "#" (hash symbol). For example, to select element with ID "txtName", then syntax would be,
1
|
$('#txtName')
|
Q23. What does $("div") will select?
Ans: This will select all the div elements on page.
Q24. How to select element having a particular class (".selected")?
Ans: $('.selected'). This selector is known as class selector. We need to prefix the class name with "." (dot).
Q25. What does $("div.parent") will select?
Ans: All the div element with parent class.
Q26. What are the fastest selectors in jQuery?
Ans: ID and element selectors are the fastest selectors in jQuery.
Q27. What are the slow selectors in jQuery?
Ans: class selectors are the slow compare to ID and element.
Q28. How jQuery selectors are executed?
Ans: Your last selectors is always executed first. For example, in below jQuery code, jQuery will first find all the elements with class ".myCssClass" and after that it will reject all the other elements which are not in "p#elmID".
Ans: This will select all the div elements on page.
Q24. How to select element having a particular class (".selected")?
Ans: $('.selected'). This selector is known as class selector. We need to prefix the class name with "." (dot).
Q25. What does $("div.parent") will select?
Ans: All the div element with parent class.
Q26. What are the fastest selectors in jQuery?
Ans: ID and element selectors are the fastest selectors in jQuery.
Q27. What are the slow selectors in jQuery?
Ans: class selectors are the slow compare to ID and element.
Q28. How jQuery selectors are executed?
Ans: Your last selectors is always executed first. For example, in below jQuery code, jQuery will first find all the elements with class ".myCssClass" and after that it will reject all the other elements which are not in "p#elmID".
1
|
$("p#elmID .myCssClass");
|
Q29. Which is fast document.getElementByID('txtName') or $('#txtName').?
Ans: Native JavaScipt is always fast. jQuery method to select txtName "$('#txtName')" will internally makes a call to document.getElementByID('txtName'). As jQuery is written on top of JavaScript and it internally uses JavaScript only So JavaScript is always fast.
Q30. Difference between $(this) and 'this' in jQuery?
Ans: this and $(this) refers to the same element. The only difference is the way they are used. 'this' is used in traditional sense, when 'this' is wrapped in $() then it becomes a jQuery object and you are able to use the power of jQuery.
Ans: Native JavaScipt is always fast. jQuery method to select txtName "$('#txtName')" will internally makes a call to document.getElementByID('txtName'). As jQuery is written on top of JavaScript and it internally uses JavaScript only So JavaScript is always fast.
Q30. Difference between $(this) and 'this' in jQuery?
Ans: this and $(this) refers to the same element. The only difference is the way they are used. 'this' is used in traditional sense, when 'this' is wrapped in $() then it becomes a jQuery object and you are able to use the power of jQuery.
1
|
$(document).ready(function(){
|
2
|
$('#spnValue').mouseover(function(){
|
3
|
alert($(this).text());
|
4
|
});
|
5
|
});
|
In below example, this is an object but since it is not wrapped in $(), we can't use jQuery method and use the native JavaScript to get the value of span element.
1
|
$(document).ready(function(){
|
2
|
$('#spnValue').mouseover(function(){
|
3
|
alert(this.innerText);
|
4
|
});
|
5
|
});
|
Q31. How do you check if an element is empty?
Ans: There are 2 ways to check if element is empty or not. We can check using ":empty" selector.
Ans: There are 2 ways to check if element is empty or not. We can check using ":empty" selector.
1
|
$(document).ready(function(){
|
2
|
if ($('#element').is(':empty')){
|
3
|
//Element is empty
|
4
|
}
|
5
|
});
|
And the second way is using the "$.trim()" method.
1
|
$(document).ready(function(){
|
2
|
if($.trim($('#element').html())=='') {
|
3
|
//Element is empty
|
4
|
}
|
5
|
});
|
Q32. How do you check if an element exists or not in jQuery?
Ans: Using jQuery length property, we can ensure whether element exists or not.
Ans: Using jQuery length property, we can ensure whether element exists or not.
1
|
$(document).ready(function(){
|
2
|
if ($('#element').length > 0){
|
3
|
//Element exists
|
4
|
});
|
5
|
});
|
Q33. What is the use of jquery .each() function?
Ans: The $.each() function is used to iterate over a jQuery object. The $.each() function can be used to iterate over any collection, whether it is an object or an array.
Q34. What is the difference between jquery.size() and jquery.length?
Ans: jQuery .size() method returns number of element in the object. But it is not preferred to use the size() method as jQuery provide .length property and which does the same thing. But the .length property is preferred because it does not have the overhead of a function call.
Q35. What is the difference between $('div') and $('<div/>') in jQuery?
Ans: $('<div/>') : This creates a new div element. However this is not added to DOM tree unless you don't append it to any DOM element.
$('div') : This selects all the div element present on the page.
Q36. What is the difference between parent() and parents() methods in jQuery?
Ans: The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree.
Q37. What is the difference between eq() and get() methods in jQuery?
Ans: eq() returns the element as a jQuery object. This method constructs a new jQuery object from one element within that set and returns it. That means that you can use jQuery functions on it.
get() return a DOM element. The method retrieve the DOM elements matched by the jQuery object. But as it is a DOM element and it is not a jQuery-wrapped object. So jQuery functions can't be used. Find out more here.
Q38. How do you implement animation functionality?
Ans: The .animate() method allows us to create animation effects on any numeric CSS property. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect.
Syntax is:
Ans: The $.each() function is used to iterate over a jQuery object. The $.each() function can be used to iterate over any collection, whether it is an object or an array.
Q34. What is the difference between jquery.size() and jquery.length?
Ans: jQuery .size() method returns number of element in the object. But it is not preferred to use the size() method as jQuery provide .length property and which does the same thing. But the .length property is preferred because it does not have the overhead of a function call.
Q35. What is the difference between $('div') and $('<div/>') in jQuery?
Ans: $('<div/>') : This creates a new div element. However this is not added to DOM tree unless you don't append it to any DOM element.
$('div') : This selects all the div element present on the page.
Q36. What is the difference between parent() and parents() methods in jQuery?
Ans: The basic difference is the parent() function travels only one level in the DOM tree, where parents() function search through the whole DOM tree.
Q37. What is the difference between eq() and get() methods in jQuery?
Ans: eq() returns the element as a jQuery object. This method constructs a new jQuery object from one element within that set and returns it. That means that you can use jQuery functions on it.
get() return a DOM element. The method retrieve the DOM elements matched by the jQuery object. But as it is a DOM element and it is not a jQuery-wrapped object. So jQuery functions can't be used. Find out more here.
Q38. How do you implement animation functionality?
Ans: The .animate() method allows us to create animation effects on any numeric CSS property. This method changes an element from one state to another with CSS styles. The CSS property value is changed gradually, to create an animated effect.
Syntax is:
1
|
(selector).animate({styles},speed,easing,callback)
|
· styles: Specifies one or more CSS properties/values to animate.
· duration: Optional. Specifies the speed of the animation.
· easing: Optional. Specifies the speed of the element in different points of the animation. Default value is "swing".
· callback: Optional. A function to be executed after the animation completes.
Simple use of animate function is,
1
|
$("btnClick").click(function(){
|
2
|
$("#dvBox").animate({height:"100px"});
|
3
|
});
|
Q39. How to disable jQuery animation?
Ans: Using jQuery property "jQuery.fx.off", which when set to true, disables all the jQuery animation. When this is done, all animation methods will immediately set elements to their final state when called, rather than displaying an effect.
Q40. How do you stop the currently-running animation?
Ans: Using jQuery ".stop()" method.
Q41. What is the difference between .empty(), .remove() and .detach() methods in jQuery?
Ans: All these methods .empty(), .remove() and .detach() are used for removing elements from DOM but they all are different.
.empty(): This method removes all the child element of the matched element where remove() method removes set of matched elements from DOM.
.remove(): Use .remove() when you want to remove 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 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.
Find out more here
Q42. Explain .bind() vs .live() vs .delegate() vs .on()
Ans: All these 4 jQuery methods are used for attaching events to selectors or elements. But they all are different from each other.
.bind(): This is the easiest and quick method to bind events. But the issue with bind() is that it doesn't work for elements added dynamically that matches the same selector. bind() only attach events to the current elements not future element. Above that 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. Because of its poor performance on large pages, this method is deprecated as of jQuery 1.7 and you should stop using it. Chaining is not properly supported using this method.
.delegate(): The .delegate() method behaves in a similar fashion to the .live() method, but instead of attaching the selector/event information to the document, you can choose where it is anchored and it also supports chaining.
.on(): Since live was deprecated with 1.7, so new method was introduced named ".on()". This method provides all the goodness of previous 3 methods and it brings uniformity for attaching event handlers.
Find out more here
Q43. What is wrong with this code line "$('#myid.3').text('blah blah!!!');"
Ans: The problem with above statement is that the selectors is having meta characters and to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar").
So the correct syntax is,
Ans: Using jQuery property "jQuery.fx.off", which when set to true, disables all the jQuery animation. When this is done, all animation methods will immediately set elements to their final state when called, rather than displaying an effect.
Q40. How do you stop the currently-running animation?
Ans: Using jQuery ".stop()" method.
Q41. What is the difference between .empty(), .remove() and .detach() methods in jQuery?
Ans: All these methods .empty(), .remove() and .detach() are used for removing elements from DOM but they all are different.
.empty(): This method removes all the child element of the matched element where remove() method removes set of matched elements from DOM.
.remove(): Use .remove() when you want to remove 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 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.
Find out more here
Q42. Explain .bind() vs .live() vs .delegate() vs .on()
Ans: All these 4 jQuery methods are used for attaching events to selectors or elements. But they all are different from each other.
.bind(): This is the easiest and quick method to bind events. But the issue with bind() is that it doesn't work for elements added dynamically that matches the same selector. bind() only attach events to the current elements not future element. Above that 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. Because of its poor performance on large pages, this method is deprecated as of jQuery 1.7 and you should stop using it. Chaining is not properly supported using this method.
.delegate(): The .delegate() method behaves in a similar fashion to the .live() method, but instead of attaching the selector/event information to the document, you can choose where it is anchored and it also supports chaining.
.on(): Since live was deprecated with 1.7, so new method was introduced named ".on()". This method provides all the goodness of previous 3 methods and it brings uniformity for attaching event handlers.
Find out more here
Q43. What is wrong with this code line "$('#myid.3').text('blah blah!!!');"
Ans: The problem with above statement is that the selectors is having meta characters and to use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[\]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\. For example, an element with id="foo.bar", can use the selector $("#foo\\.bar").
So the correct syntax is,
1
|
$('#myid\\.3').text('blah blah!!!');
|
Q44. How to create clone of any object using jQuery?
Ans: jQuery provides clone() method which performs a deep copy of the set of matched elements, meaning that it copies the matched elements as well as all of their descendant elements and text nodes.
1
|
$(document).ready(function(){
|
2
|
$('#btnClone').click(function(){
|
3
|
$('#dvText').clone().appendTo('body');
|
4
|
return false;
|
5
|
});
|
6
|
});
|
Q45. Does events are also copied when you clone any element in jQuery?
Ans: As explained in previous question, using clone() method, we can create clone of any element but the default implementation of the clone() method doesn't copy events unless you tell the clone() method to copy the events. The clone() method takes a parameter, if you pass true then it will copy the events as well.
Ans: As explained in previous question, using clone() method, we can create clone of any element but the default implementation of the clone() method doesn't copy events unless you tell the clone() method to copy the events. The clone() method takes a parameter, if you pass true then it will copy the events as well.
1
|
$(document).ready(function(){
|
2
|
$("#btnClone").bind('click', function(){
|
3
|
$('#dvClickme').clone(true).appendTo('body');
|
4
|
});
|
Q46. What is difference between prop and attr?
Ans: attr(): Get the value of an attribute for the first element in the set of matched elements. Whereas,.prop(): (Introduced in jQuery 1.6) Get the value of a property for the first element in 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 use prop() to get values of elements which is modified via javascript/jquery , as it gives you the original value of an element's current state. Find out more here.
Q47. What is event.PreventDefault?
Ans: The event.preventDefault() method stops the default action of an element from happening. For example, Prevents a link from following the URL.
Q48. What is the difference between event.PreventDefault and event.stopPropagation?
Ans: event.preventDefault(): Stops the default action of an element from happening.
event.stopPropagation(): Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing.
Q49. What is the difference between event.PreventDefault and "return false"?
Ans: e.preventDefault() will prevent the default event from occurring, e.stopPropagation() will prevent the event from bubbling up and return false will do both.
Q50. What is the difference between event.stopPropagation and event.stopImmediatePropagation?
Ans: event.stopPropagation() allows other handlers on the same element to be executed, while event.stopImmediatePropagation() prevents every event from running. For example, see below jQuery code block.
Ans: attr(): Get the value of an attribute for the first element in the set of matched elements. Whereas,.prop(): (Introduced in jQuery 1.6) Get the value of a property for the first element in 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 use prop() to get values of elements which is modified via javascript/jquery , as it gives you the original value of an element's current state. Find out more here.
Q47. What is event.PreventDefault?
Ans: The event.preventDefault() method stops the default action of an element from happening. For example, Prevents a link from following the URL.
Q48. What is the difference between event.PreventDefault and event.stopPropagation?
Ans: event.preventDefault(): Stops the default action of an element from happening.
event.stopPropagation(): Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event. For example, if there is a link with a click method attached inside of a DIV or FORM that also has a click method attached, it will prevent the DIV or FORM click method from firing.
Q49. What is the difference between event.PreventDefault and "return false"?
Ans: e.preventDefault() will prevent the default event from occurring, e.stopPropagation() will prevent the event from bubbling up and return false will do both.
Q50. What is the difference between event.stopPropagation and event.stopImmediatePropagation?
Ans: event.stopPropagation() allows other handlers on the same element to be executed, while event.stopImmediatePropagation() prevents every event from running. For example, see below jQuery code block.
1
|
$("p").click(function(event){
|
2
|
event.stopImmediatePropagation();
|
3
|
});
|
4
|
$("p").click(function(event){
|
5
|
// This function won't be executed
|
6
|
$(this).css("background-color", "#f00");
|
7
|
});
|
If event.stopPropagation was used in previous example, then the next click event on p element which changes the css will fire, but in case event.stopImmediatePropagation(), the next p click event will not fire.
Q51. How to check if number is numeric while using jQuery 1.7+?
Ans: Using "isNumeric()" function which was introduced with jQuery 1.7.
Q52. How to check data type of any variable in jQuery?
Ans: Using $.type(Object) which returns the built-in JavaScript type for the object.
Q53. How do you attach a event to element which should be executed only once?
Ans: Using jQuery one() method. This attaches a handler to an event for the element. The handler is executed at most once per element. In simple terms, the attached function will be called only once.
Q51. How to check if number is numeric while using jQuery 1.7+?
Ans: Using "isNumeric()" function which was introduced with jQuery 1.7.
Q52. How to check data type of any variable in jQuery?
Ans: Using $.type(Object) which returns the built-in JavaScript type for the object.
Q53. How do you attach a event to element which should be executed only once?
Ans: Using jQuery one() method. This attaches a handler to an event for the element. The handler is executed at most once per element. In simple terms, the attached function will be called only once.
1
|
$(document).ready(function() {
|
2
|
$("#btnDummy").one("click", function() {
|
3
|
alert("This will be displayed only once.");
|
4
|
});
|
5
|
});
|
Q54. Can you include multiple version of jQuery? If yes, then how they are executed?
Ans: Yes. Multiple versions of jQuery can be included in same page.
Q55. In what situation you would use multiple version of jQuery and how would you include them?
Ans: Well, it is quite possible that the jQuery plugins which are used are dependent on older version but for your own jQuery code, you would like to use newer version. So because of this dependency, multiple version of jQuery may required sometimes on single page.
Below code shows how to include multiple version of jQuery.
Ans: Yes. Multiple versions of jQuery can be included in same page.
Q55. In what situation you would use multiple version of jQuery and how would you include them?
Ans: Well, it is quite possible that the jQuery plugins which are used are dependent on older version but for your own jQuery code, you would like to use newer version. So because of this dependency, multiple version of jQuery may required sometimes on single page.
Below code shows how to include multiple version of jQuery.
1
|
<script type='text/javascript' src='js/jquery_1.9.1.min.js'></script>
|
2
|
3
|
<script type='text/javascript'>
|
4
|
var $jq = jQuery.noConflict();
|
5
|
</script>
|
6
|
7
|
<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.
Q56. Is it possible to hold or delay document.ready execution for sometime?
Ans: Yes, its possible. With Release of jQuery 1.6, a new method "jQuery.holdReady(hold)" was introduced. This method allows to delay the execution of document.ready() event. document.ready() event is called as soon as your DOM is ready but sometimes there is a situation when you want to load additional JavaScript or some plugins which you have referenced.
Q56. Is it possible to hold or delay document.ready execution for sometime?
Ans: Yes, its possible. With Release of jQuery 1.6, a new method "jQuery.holdReady(hold)" was introduced. This method allows to delay the execution of document.ready() event. document.ready() event is called as soon as your DOM is ready but sometimes there is a situation when you want to load additional JavaScript or some plugins which you have referenced.
1
|
|
2
|
$.holdReady(true);
|
3
|
$.getScript("myplugin.js", function() {
|
4
|
$.holdReady(false);
|
5
|
});
|
Q57. What is chaining in jQuery?
Ans: Chaining is one of the most powerful feature of jQuery. In jQuery, Chaining means to connect multiple functions, events on selectors. It makes your code short and easy to manage and it gives better performance. The chain starts from left to right. So left most will be called first and so on.
Ans: Chaining is one of the most powerful feature of jQuery. In jQuery, Chaining means to connect multiple functions, events on selectors. It makes your code short and easy to manage and it gives better performance. The chain starts from left to right. So left most will be called first and so on.
1
|
$(document).ready(function(){
|
2
|
$('#dvContent').addClass('dummy');
|
3
|
$('#dvContent').css('color', 'red');
|
4
|
$('#dvContent').fadeIn('slow');
|
5
|
});
|
The above jQuery code sample can be re-written using chaining. See below.
1
|
$(document).ready(function(){
|
2
|
$('#dvContent').addClass('dummy')
|
3
|
.css('color', 'red')
|
4
|
.fadeIn('slow');
|
5
|
});
|
Not only functions or methods, chaining also works with events in jQuery.
Q58. How does caching helps and how to use caching in jQuery?
Ans: Caching is an area which can give you awesome performance, if used properly and at the right place. While using jQuery, you should also think about caching. For example, if you are using any element in jQuery more than one time, then you must cache it. See below code.
Q58. How does caching helps and how to use caching in jQuery?
Ans: Caching is an area which can give you awesome performance, if used properly and at the right place. While using jQuery, you should also think about caching. For example, if you are using any element in jQuery more than one time, then you must cache it. See below code.
1
|
$("#myID").css("color", "red");
|
2
|
//Doing some other stuff......
|
3
|
$("#myID").text("Error occurred!");
|
4
|
|
Now in above jQuery code, the element with #myID is used twice but without caching. So both the times jQuery had to traverse through DOM and get the element. But if you have saved this in a variable then you just need to reference the variable. So the better way would be,
1
|
var $myElement = $("#myID").css("color", "red");
|
2
|
//Doing some other stuff......
|
3
|
$myElement.text("Error occurred!");
|
4
|
|
So now in this case, jQuery won't need to traverse through the whole DOM tree when it is used second time. So in jQuery, Caching is like saving the jQuery selector in a variable. And using the variable reference when required instead of searching through DOM again.
Q59. You get "jquery is not defined" or "$ is not defined" error. What could be the reason?
Ans: There could be many reasons for this.
Q59. You get "jquery is not defined" or "$ is not defined" error. What could be the reason?
Ans: There could 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 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.
Q60. How to write browser specific code using jQuery?
Ans: Using jQuery.browser property, we can write browser specific code. This property contains flags for the useragent, read from navigator.userAgent. This property was removed in jQuery 1.9.
Q61. Can we use jQuery to make ajax request?
Ans: Yes. jQuery can be used for making ajax request.
Q62. What are various methods to make ajax request in jQuery?
Ans: Using below jQuery methods, you can make ajax calls.
· 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.
Find out more here.
Q63. Is there any advantage of using $.ajax() for ajax call against $.get() or $.post()?
Ans: By using jQuery post()/ jQuery get(), you always trust the response from the server and you believe it is going to be successful all the time. Well, it is certainly not a good idea to trust the response. As there can be n number of reason which may lead to failure of response.
Where jQuery.ajax() is jQuery's low-level AJAX implementation. $.get and $.post are higher-level abstractions that are often easier to understand and use, but don't offer as much functionality (such as error callbacks). Find out more here.
Q64. What are deferred and promise object in jQuery?
Ans: Deferred and promise are part of jQuery since version 1.5 and they help in handling asynchronous functions like Ajax. Find out more here.
Q65. Can we execute/run multiple Ajax request simultaneously in jQuery? If yes, then how?
Ans: Yes, it is possible to execute multiple Ajax request simultaneously or in parallel. Instead of waiting for first ajax request to complete and then issue the second request is time consuming. The better approach to speed up things would be to execute multiple ajax request simultaneously.
Using jQuery .when() method which provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events. Find out more here.
Q66. Can you call C# code-behind method using jQuery? If yes,then how?
Ans: Yes. We can call C# code-behind function via $.ajax. But for do that it is compulsory to mark the method as WebMethod.
Q67. Which is the latest version of jQuery library?
Ans: The latest version (when this post is written) of jQuery is 1.10.2 or 2.0.3. jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8.
Q68. Does jQuery 2.0 supports IE?
Ans: No. jQuery 2.0 has no support for IE 6, IE 7 and IE 8.
Q69. What are source maps in jQuery?
Ans: In case of jQuery, Source Map is nothing but 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. Find out more here.
Q70. How to use migrate jQuery plugin?
Ans: 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 possible 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, all you need to do is to provide reference of jQuery Migrate Plugin. Find out more here.
Q71. Is it possible to get value of multiple CSS properties in single statement?
Ans: Well, before jQuery 1.9 release it was not possible but one of the new feature of jQuery 1.9 was .css() multi-property getter.
Q63. Is there any advantage of using $.ajax() for ajax call against $.get() or $.post()?
Ans: By using jQuery post()/ jQuery get(), you always trust the response from the server and you believe it is going to be successful all the time. Well, it is certainly not a good idea to trust the response. As there can be n number of reason which may lead to failure of response.
Where jQuery.ajax() is jQuery's low-level AJAX implementation. $.get and $.post are higher-level abstractions that are often easier to understand and use, but don't offer as much functionality (such as error callbacks). Find out more here.
Q64. What are deferred and promise object in jQuery?
Ans: Deferred and promise are part of jQuery since version 1.5 and they help in handling asynchronous functions like Ajax. Find out more here.
Q65. Can we execute/run multiple Ajax request simultaneously in jQuery? If yes, then how?
Ans: Yes, it is possible to execute multiple Ajax request simultaneously or in parallel. Instead of waiting for first ajax request to complete and then issue the second request is time consuming. The better approach to speed up things would be to execute multiple ajax request simultaneously.
Using jQuery .when() method which provides a way to execute callback functions based on one or more objects, usually Deferred objects that represent asynchronous events. Find out more here.
Q66. Can you call C# code-behind method using jQuery? If yes,then how?
Ans: Yes. We can call C# code-behind function via $.ajax. But for do that it is compulsory to mark the method as WebMethod.
Q67. Which is the latest version of jQuery library?
Ans: The latest version (when this post is written) of jQuery is 1.10.2 or 2.0.3. jQuery 2.x has the same API as jQuery 1.x, but does not support Internet Explorer 6, 7, or 8.
Q68. Does jQuery 2.0 supports IE?
Ans: No. jQuery 2.0 has no support for IE 6, IE 7 and IE 8.
Q69. What are source maps in jQuery?
Ans: In case of jQuery, Source Map is nothing but 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. Find out more here.
Q70. How to use migrate jQuery plugin?
Ans: 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 possible 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, all you need to do is to provide reference of jQuery Migrate Plugin. Find out more here.
Q71. Is it possible to get value of multiple CSS properties in single statement?
Ans: Well, before jQuery 1.9 release it was not possible but one of the new feature of jQuery 1.9 was .css() multi-property getter.
1
|
var propCollection = $("#dvBox").css([ "width", "height", "backgroundColor" ]);
|
In this case, the propCollection will be an array and it will look something like this.
1
|
{
|
2
|
width: "100px",
|
3
|
height: "200px",
|
4
|
backgroundColor: "#FF00FF"
|
5
|
}
|
Q72. How do you stop the currently-running animation, remove all queued animations, and complete all animations for the matched elements?
Ans: It can be done via calling .stop([clearQueue ] [, jumpToEnd ]) method and by passing both the parameters as true.
Q73. What is finish method in jQuery?
Ans: The .finish() method stops all queued animations and places the element(s) in their final state. This method was introduced in jQuery 1.9.
Q74. What is the difference between calling stop(true,true) and finish method?
Ans: 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.
Q75. Consider a scenario where things can be done easily with javascript, would you still prefer jQuery?
Ans: No. If things can be done easily via CSS or JavaScript then You should not think about jQuery. Remember, jQuery library always comes with xx kilobyte size and there is no point of wasting bandwidth.
Q76. Can we use protocol less URL while referencing jQuery from CDNs?
Ans: Yes. Below code is completely valid.
Ans: It can be done via calling .stop([clearQueue ] [, jumpToEnd ]) method and by passing both the parameters as true.
Q73. What is finish method in jQuery?
Ans: The .finish() method stops all queued animations and places the element(s) in their final state. This method was introduced in jQuery 1.9.
Q74. What is the difference between calling stop(true,true) and finish method?
Ans: 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.
Q75. Consider a scenario where things can be done easily with javascript, would you still prefer jQuery?
Ans: No. If things can be done easily via CSS or JavaScript then You should not think about jQuery. Remember, jQuery library always comes with xx kilobyte size and there is no point of wasting bandwidth.
Q76. Can we use protocol less URL while referencing jQuery from CDNs?
Ans: Yes. Below code is completely valid.
1
|
<script type='text/javascript'src='//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
|
Q77. What is the advantage of using protocol less URL while referencing jQuery from CDNs?
Ans: It is quite useful when you are moving from HTTP to HTTPS url. You need to make sure that correct protocol is used for referencing jQuery library as pages served via SSL should contain no references to content served through unencrypted connections.
"protocol-less" URL is the best way to reference third party content that’s available via both HTTP and HTTPS. When a URL’s protocol is omitted, the browser uses the underlying document’s protocol instead. Find out more here.
Q78. What is jQuery plugin and what is the advantage of using plugin?
Ans: 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.
Q79. What is jQuery UI?
Ans: jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library that can be used to build interactive web applications.
Q80. What is the difference between jQuery and jQuery UI?
Ans: jQuery is the core library. jQueryUI is built on top of it. If you use jQueryUI, you must also include jQuery.
Ans: It is quite useful when you are moving from HTTP to HTTPS url. You need to make sure that correct protocol is used for referencing jQuery library as pages served via SSL should contain no references to content served through unencrypted connections.
"protocol-less" URL is the best way to reference third party content that’s available via both HTTP and HTTPS. When a URL’s protocol is omitted, the browser uses the underlying document’s protocol instead. Find out more here.
Q78. What is jQuery plugin and what is the advantage of using plugin?
Ans: 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.
Q79. What is jQuery UI?
Ans: jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library that can be used to build interactive web applications.
Q80. What is the difference between jQuery and jQuery UI?
Ans: jQuery is the core library. jQueryUI is built on top of it. If you use jQueryUI, you must also include jQuery.
What is Initial release of JQuery Mobile?
October 16, 2010
Question: What is Latest version of jQuery Mobile?
Version: 1.4.5
Dated: October 31, 2014
Question: In which language, jQuery mobile is written?
JavaScript
Question: Where it is used?
It is "Mobile application framework" which is used for creating mobile web applications.
Question: What is offical website of jQuery Mobile?
http://jquerymobile.com/
Question: What are Features of jQuery Mobile?
· Compatible with all major desktop browsers as well as all major mobile platforms (Android, iOS, Windows Phone, Blackberry, WebOS, Symbian)
· Built on top of jQuery core.
· Lightweight to optimize speed.
· The same underlying codebase will automatically scale to any screen.
· HTML5-driven.
· AJAX-powered navigation with animated page.
· UI widgets
Question: Why Use jQuery Mobile?
1. Write Less, Do more
2. Its works on Android, Blackberry, iOS and Iphone
3. Its optimized
Question: Describe few HTML tags used in jQuery Mobile?
data-role="page": Page displayed in the browser.
data-role="header": Creates a toolbar at the top of the page.
data-role="main": Content of the page, like text, images, buttons and forms etc.
"ui-content": Adds extra padding and margin inside the page content
data-role="footer": creates a toolbar at the bottom of the page
Question: How to Add Back Button?
1
|
<aclass="ui-btn"data-rel="back"href="#">Go Back</a>
|
Question: What is jQuery Mobile Themeing?
jQuery Mobile provides a powerful theming that allows developers to customize color schemes & CSS aspects of UI features.
JavaScript
(1) What is event bubbling and capturing in JavaScript?
Event bubbling is series of events when : An event is triggered on the inner most element first and then it triggers on the parent elements in nested order.
DOM elements could be nested inside each other. The handler of the parent works even if you click on it’s child. Event bubbling can make this happen.
Event Capturing is the opposite of bubbling where the event is triggered on the outer most element and then it triggers the inner children in nested order.
(2) What is a closure in JavaScript?
JavaScript allows you to declare a function within another function, and the local variables still can be accessible even after returning from the function you called.
In other words, a closure is the local variables for a function which is kept alive after the function has returned.
An example :
function goodMorning(name) {
var text = ‘Good Morning ‘ + name; // local variable
var goodMorningAlert = function() { alert(text); }
return sayAlert;
}
var text = ‘Good Morning ‘ + name; // local variable
var goodMorningAlert = function() { alert(text); }
return sayAlert;
}
var goodMorningAlert2 = goodMorning(‘Bob’);
goodMorningAlert2();
goodMorningAlert2();
In the example above, when goodMorningAlert2() will be executed, you will see output as an alert with “Good Morning Bob”.
In short, in JavaScript, if you use the function keyword inside another function, you are creating a closure.
(3) What is a callback function in JavaScript?
(4) What are various methods you’d use to embed JavaScript onto a webpage?
(5) What is the difference between GET and POST methods in HTML form?
(4) What are various methods you’d use to embed JavaScript onto a webpage?
(5) What is the difference between GET and POST methods in HTML form?
When you use a GET method, key and values will be appended at the end of the URL as a query string. GET method is not recommended to use when you are passing sensitive data over the internet.
While sending data, the GET method appends the data to the URL. And the length of a URL is limited. Maximum URL length is 2048 characters supported by latest browsers.
POST is used to pass sensitive data as it’s not appended and displayed within the URL. There is no limitation as to how much data can be passed using a POST method.
(6) What does continue and break statements do in JS?
The continue statement breaks only one iteration in the current loop if a defined condition occurs. and it continues with the next iteration in the loop.
The break statement breaks out of the loop. And it lets the code continue executing after the loop.
(7) What is the difference between windows.onload and onDocumentReady?
The onload event does not fire until the last element of the page is loaded including CSS and images etc. There could be a huge delay before onload code on the page is executed.
onDocumentReady will be able to execute code as long as DOM has been is built; without waiting for the elements to be loaded, such as images. That means there will be a faster code execution.
(8) what is a race condition?
When execution of a certain method or an event call is critically dependent on an another method or event; and if the sequence is not maintained, race condition occurs. As an example; you’re loading an external Javascript on your page and then calling a function from that external JS. Now at the run time if the external JS is not loaded for any reason and your function is already called and looking for that code execution, it’s not going to be executed. This situation is called race condition.
(9) What is JS namespacing? How and where is it used?
adding answer soon…
(10) Tell me datatypes that are supported in JavaScript.
JavaScript supports various data types such as numbers, strings, arrays, objects etc. You can also directly assign expressions. Such as :
var datapoint = a * 10; // Number assigned by an expression literal