CAP214CA3
CAP214CA3
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body>
</html>
jQuery selector: jQuery selectors are one of the most important parts of the jQuery library.
jQuery selectors allow you to select and manipulate HTML element(s).
jQuery selectors are used to "find" (or select) HTML elements based on their name, id, classes,
types, attributes, values of attributes and much more. It's based on the existing CSS Selectors,
and in addition, it has some own custom selectors.All selectors in jQuery start with the dollar
sign and parentheses: $().
Example:
The jQuery element selector selects elements based on the element name.
$("p")
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element.
An id should be unique within a page, so you should use the #id selector when you want to find a
single, unique element.To find an element with a specific id, write a hash character, followed by
the id of the HTML element:
$("#test")
When a user clicks on a button, the element with id="test" will be hidden
CODE:
<html>
<head>
<body>
</body>
<tr>
<th>Name</th>
<th>age</th>
</tr>
<tr>
<td>Mike</td>
<td>40</td>
</tr>
<tr>
<td>Adam</td>
<td>50</td>
</tr>
<tr>
<td>Baldwin</td>
<td>34</td>
</tr>
<tr>
<td>Miller</td>
<td>40</td>
</tr>
</table>
</head>
</html>
<script>
$(document).ready(function()
$("tr:even").css("background-color", "#F4F4F8");
$("tr:odd").css("background-color", "#EFF1F1");
});
</script>
5. Multiple Choice Questions. Please select one right option for each question
ANSWERS:
Answers are marked with yellow color
1. What is the correct jQuery code to set the background color of all p elements to red?
A.$("p").layout("background-color","red");
B. $("p").manipulate("background-color","red");
C. $("p").css("background-color","red");
D. $("p").style("background-color","red");
2. Which jQuery method should be used to deal with name conflicts?
A. noNameConflict()
B. noConflict()
C. nameConflict()
D. conflict()
3. var ps = $("p");
ps will be..
A. A linked list
B. A hash or dictionary
C. An array
D. A jQuery object
4. $(document).ready(function() {
// Some code.
});
The above code is used to..
A. Make sure no code is executed till the entire page is fully loaded
B. Make sure no code is executed till the DOM is fully loaded
C. Both A and B
D. Neither A nor B
5. Query.noConflict(true) is used to..
A. Free up the $ symbol for use by other libraries
B. Improve compatibility
C. Remove all jQuery variables from the global scope
D. All of the above
6. $('p').click(function(){
// Code here
});
Inside the commented section, the value of the variable this is a..
A. Array
B. String
C. Reference to the DOM node
D. jQuery object