Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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 :-

<title> Title 1 </title>
<script type = "text/javascript">
  alert ("Hi!!!");
  document.bgColor = "RED";
<title> Title 2 </title>
<body bgcolor = "YELLOW">
Hi!!! Again
<title> TITLE 2 </title>
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!
Reply With Quote
  #2 (permalink)  
Old July 27th, 2011, 04:32 PM
jmcpeak's Avatar
Wrox Author
Points: 467, Level: 7
Points: 467, Level: 7 Points: 467, Level: 7 Points: 467, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Nov 2005
Location: , Texas, USA.
Posts: 87
Thanks: 0
Thanked 18 Times in 17 Posts

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:

    <title>Title 1</title>
    document.bgColor = "red";
    document.bgColor = "yellow";

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:41 PM.

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