jQuery Quiz I

1. In jQuery terminology, what is the difference between the “jQuery function” and the “jQuery object”?
Answer
  • The jQuery function is the value of jQuery or of $ This is the function that creates jQuery objects and registers handlers to be invoked when the DOM is ready;
  • A jQuery object is an object returned by the jQuery function. A jQuery object represents a set of document elements and can also be called a “jQuery result”, a “jQuery set”, or a “wrapped set”.
2. Write jQuery code to find all h1 elements that are children of a div element and make their background color red.

<body>
<h1>abc </h1> <br> <div>

<h1>div-1 </h1> <h1>div-2 </h1>
</div>
<h1>xyz </h1>
</body>

Answer
                $(document).ready(function(){
                    $("div h1").css("background-color", "red");
                });
            
3. Use a jQuery method to insert the text "YES!" at the end of the <p> element

<!DOCTYPE html>
<html>
<head>
<script>

<!- INSERT YOUR CODE HERE -->

$(document).ready(function () {
$("p").append(document.createTextNode(" YES"));
});
</script>
</head>
<body>

<p> Is jQuery FUN or what? YES </p>

</body>
</html>