InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Can you tell the difference between prop() and attr()s? |
Answer»
A JavaScript library called jQuery makes it simple to construct dynamic web pages. It contributes to the efficiency and interactivity of web applications. It also facilitates the usage of a number of functions that may be used to alter data, which speeds up the development process. JQuery has some important uses like - DOM manipulations, Availability of different plugins according to the work, Animation and AJAX Support, Support for Cross browsers, etc. jQuery is a lightweight library that can be easily integrated into any website. We have seen all the most frequently asked questions related to jquery in the interview. Additional Interview Resources
|
|
| 2. |
Can you provide an example of chaining using a code snippet? |
|
Answer» Old Code: $(document).ready(function(){$('#id').addClass('ib); $('#id').css('color', 'blue); $('#id').fadeIn('slow'); }); New Code after Chaining: $(document).ready(function(){$('#id').addClass('ib) .css('color', 'blue') .fadeIn('slow); }); |
|
| 3. |
Consider the below code snippet and assume that there are 5 elements on the page. What is the difference between the start and end times displayed? |
|
Answer» function getMinsSeconds() { var dt = new Date(); return dt.getMinutes()+":"+dt.getSeconds(); } $( "input" ).on( "click", function() { $( "p" ).append( "Start: " + getMinsSeconds() + "<br />" ); $( "div" ).each(function( i ) { $( this ).fadeOut( 1000 * ( i * 2 ) ); }); $( "div" ).promise().done(function() { $( "p" ).append( "End: " + getMinsSeconds() + "<br />" ); }); });
|
|
| 4. |
Write A Jquery Code Snippet To Sort A String Array? |
|
Answer» $(document).ready(function(){ var arr = [ "jQuery","Interview","Questions","By","InterviewBit"]; sortedArr = arr.sort(); $("#elementId").html(sortedArr.join("")); }); The Output will be ["By","InterviewBit","Interview","jQuery","Questions"] |
|
| 5. |
Explain the .promise() method in jQuery. |
Answer»
|
|
| 6. |
Can you write a jQuery code selector that needs to be used for querying all elements whose ID ends with string “IB”? |
|
Answer» We can use the following selector: $("[id$='IB']") |
|
| 7. |
How do you disable elements in Jquery Using "attr"? |
|
Answer» $('class_or_id_of_element_to_disable').attr('disabled', true); $('class_or_id_of_element_to_disable').attr('disabled', false); |
|
| 8. |
Which of the two lines of code below is more efficient and why? |
|
Answer» document.getElementById("interviewBit"); OR $("#interviewBit");
|
|
| 9. |
Write a code snippet for preventing the default behavior of the submit button for performing another event. |
|
Answer» <script> $(document).ready(function(){ $("#submitButton").click(function(event){ event.preventDefault(); }); }); </script> |
|
| 10. |
Can you explain the difference between jQuery.get() and jQuery.ajax()? |
Answer»
|
|
| 11. |
Consider the following code that exists in following HTML with the CSS: |
|
Answer» <div id="expand"></div> <style> div#expand{ width: 50px; height: 50px; background-color: gray; } </style> Write jQuery code to animate the #expand div, expanding it from 50 * 50 pixels to 300 * 300 pixels within five seconds. We can do this by using the animate() function. We first need to have access to the div element which has id value of expand and then apply animate function on the element as follows: $("#expand").animate({ width: "300px", height: "300px", }, 5000 ); |
|
| 12. |
Write a jQuery code to create and delete cookies from the browser. |
|
Answer» There is no direct way to access the cookies using jquery. We can easily do this with the help of pure javascript. To work with cookies in jQuery, you must install the Dough cookie plugin or any other cookies plugins. The dough is simple to use and offers a number of useful capabilities.
|
|
| 13. |
What does the following code do? |
|
Answer» $( "div#firstDiv, div.firstDiv, ol#items > [name$='firstDiv']" )
|
|
| 14. |
How to perform jQuery AJAX requests? |
Answer»
url: "resourceURL", async: false, success: function(result){ $("div").html(result); }, error: function(xhr){ alert("An error occured: " + xhr.status + " " + xhr.statusText); } }); |
|