Wrox Programmer Forums
|
BOOK: Beginning JavaScript 4th Edition
This is the forum to discuss the Wrox book Beginning JavaScript, 4th Edition by Paul Wilton, Jeremy McPeak; ISBN: 978-0-470-52593-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript 4th Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2011, 01:02 PM
Registered User
 
Join Date: Jul 2011
Posts: 4
Thanks: 3
Thanked 0 Times in 0 Posts
Default 1st Chapter Example 2

It is mentioned that the program is interpreted from top to bottom. However, there is some odd behaviour given by the code below :-

Code:
<html>
<head>
<title> Title 1 </title>
</head>
<body>
HI!!!!
</body>
<script type = "text/javascript">
  alert ("Hi!!!");
  document.bgColor = "RED";
</script>
<head>
<title> Title 2 </title>
</head>
<body bgcolor = "YELLOW">
Hi!!! Again
</body>
<head>
<title> TITLE 2 </title>
</head>
</html>
I have mentioned the background colour to be yellow later in the program, but the webpage is being created red in colour, as mentioned in the <script>-</script> block!
Thanks!
 
Old July 27th, 2011, 04:32 PM
jmcpeak's Avatar
Wrox Author
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 18 Times in 17 Posts
Default

Howdy, Ashu2912.

You're seeing this behavior because of the markup. According to the HTML specification, an HTML document should have only one head element and one body element. Since you have two body elements, the browser uses the first body element and ignores the second element (but not it's content--in fact, the second element's content is appended to the first body). Because the second body element is ignored, the document's background doesn't change to yellow.

The same behavior is exhibited in the title elements. Your document has three head elements with three title elements. The browser uses the first title element and ignores the second and third.

To give you an idea of what the book was meaning, use this code:

Code:
<html>
<head>
    <title>Title 1</title>
</head>
<body>
<script>
    document.bgColor = "red";
    document.bgColor = "yellow";
</script>
</body>
</html>

Last edited by jmcpeak; July 27th, 2011 at 04:38 PM..
The Following User Says Thank You to jmcpeak For This Useful Post:
Ashu2912 (July 28th, 2011)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 16: 1st 'Try It Out' Web.config error jee26 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 7 September 21st, 2008 09:35 AM
Chapter 2 - 1st exercise gomesdir BOOK: Beginning JavaServer Pages 4 April 6th, 2006 08:13 PM
Chapter 13, can't do 1st example beg. page 481 mjoh44 JSP Basics 2 August 16th, 2004 09:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.