0% found this document useful (0 votes)
14 views

jQuery_Exam_Answers_Final

The document provides a comprehensive answer sheet for jQuery, covering essential concepts such as prerequisites for learning jQuery, its necessity, and the use of selectors and events. It includes practical jQuery code examples for various tasks like checking scroll direction, disabling right-click, and handling broken images. Additionally, it explains methods for installing jQuery and commonly used event methods.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

jQuery_Exam_Answers_Final

The document provides a comprehensive answer sheet for jQuery, covering essential concepts such as prerequisites for learning jQuery, its necessity, and the use of selectors and events. It includes practical jQuery code examples for various tasks like checking scroll direction, disabling right-click, and handling broken images. Additionally, it explains methods for installing jQuery and commonly used event methods.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

JQuery (402) - Answer Sheet

Q1) Attempt any FIVE of the following

1. What should you know before learning jQuery?

Before learning jQuery, you should have a basic understanding of:

- HTML: To structure web pages.

- CSS: To style elements and understand selectors.

- JavaScript: Since jQuery is a JavaScript library, knowing JavaScript fundamentals like variables,

functions, and events is essential.

2. Why is jQuery required?

jQuery is required because:

- It simplifies JavaScript programming.

- It provides easy DOM manipulation.

- It ensures cross-browser compatibility.

- It allows AJAX calls and animations with minimal code.

3. What is the use of jQuery Selector?

jQuery selectors are used to select and manipulate HTML elements. They allow you to apply

styles, handle events, and perform operations on elements.

Example:

$("p").css("color", "red");
4. What is an event in jQuery?

An event in jQuery is an action that occurs in the browser, such as:

- Clicking a button (click event)

- Typing in an input field (keyup event)

- Loading a webpage (ready event)

Example:

$("#myButton").click(function() {

alert("Button clicked!");

});

5. What is traversing?

Traversing in jQuery allows navigation through elements in the DOM tree. It helps to find elements

relative to another.

Example:

$("p").parent(); // Selects the parent of a paragraph element.

6. What is the use of jQuery animate() method?

The animate() method is used to create custom animations on HTML elements.

Example:

$("#box").animate({ left: '250px', opacity: '0.5' }, 1000);

7. What is the use of jQuery remove() method?

The remove() method deletes an element from the DOM.


Example:

$("#myDiv").remove();

Q2) Attempt any FIVE of the following

1. Write a jQuery code to check whether the page scrolls from bottom to top and vice versa.

$(window).scroll(function () {

if ($(this).scrollTop() > 100) {

console.log("Scrolling Down");

} else {

console.log("Scrolling Up");

});

2. Write a jQuery code to disable right-click menu on an HTML page.

$(document).on("contextmenu", function (e) {

e.preventDefault();

});

3. Write a jQuery code to disable right-click of mouse on page.

$(document).ready(function () {

$(document).bind("contextmenu", function (e) {

return false;

});

});
4. Write a jQuery code to check whether jQuery is loaded or not.

if (window.jQuery) {

console.log("jQuery is loaded.");

} else {

console.log("jQuery is not loaded.");

5. Write a jQuery code to fix broken images automatically.

$("img").on("error", function () {

$(this).attr("src", "default.jpg");

});

6. Write a jQuery code to disable a link.

$("a").click(function (e) {

e.preventDefault();

});

Q3) Attempt any ONE of the following

1. How is jQuery installed (added) in web pages?

There are two ways to include jQuery in a web page:

- Using a CDN (Content Delivery Network):

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

- Downloading jQuery and adding it locally:

- Download jQuery from the official website.

- Save it in your project folder and include it:


<script src="jquery-3.6.0.min.js"></script>

2. Explain any two commonly used event methods in jQuery.

- click() Event: Triggers an action when an element is clicked.

$("#btn").click(function() {

alert("Button Clicked!");

});

- hover() Event: Triggers two functions when the mouse enters and leaves an element.

$("#box").hover(

function() { $(this).css("background-color", "yellow"); },

function() { $(this).css("background-color", "white"); }

);

3. Explain fading methods.

Fading methods in jQuery control element visibility by adjusting opacity:

- fadeIn(speed) - Gradually makes an element visible.

$("#box").fadeIn(1000);

- fadeOut(speed) - Gradually hides an element.

$("#box").fadeOut(1000);

- fadeToggle(speed) - Toggles visibility.

$("#box").fadeToggle(1000);

- fadeTo(speed, opacity) - Changes opacity to a given value.

$("#box").fadeTo(1000, 0.5);

You might also like