Java Reference
In-Depth Information
which accepts a string of HTML that is written to the page. The way in which html() writes HTML
into the page is different from document.write(). Instead, jQuery's html() method uses the
innerHTML DOM property to set the HTML inside a DOM object (in this case document.body).
As you can see from this example, chaining is a handy way of performing multiple tasks on one object,
and jQuery is built around this concept.
Use this code to test your jQuery installation. Open ch15_examp1_jq.htm and add in the second
<script/> element shown in the following code:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Chapter 15: Example 2 jQuery</title>
<script type=”text/javascript” src=”jquery-1.3.2.min.js”></script>
<script type=”text/javascript”>
function document_ready($)
{
$(document.body).attr(“bgColor”, “yellow”)
.html(“<h1>Hello, jQuery World!</h1>”);
}
$(document).ready(document_ready);
</script>
</head>
<body>
</body>
</html>
Save this as ch15_examp2_jq.htm, and open it in your browser. You should see something like
Figure 15-1.
Figure 15-1
Search WWH ::




Custom Search