user2130915
user2130915

Reputation: 9

use of head tag in between div tag

this is sample code i tried n its working

 <html>
 <head>
 <style>
 <!--
  .execute { background-color: red; height: 25px; }
 -->
 </style>
  <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js">
  </script>

<!-- Let's register a onClick handle for any .execute div. -->

</head>
 <body>
<div class="execute">
  <head>
   <script>
  dojo.ready(function()  // Dojo will run this after being initialized
  {
      // Get A list of all tags with id execute and add a event onClick
      dojo.query(".execute").connect("onclick", function(evt)
      {
          alert("Event triggered!");
          // ...
      });
  });
</script>
  </head>
<body>
  Click me 1
 </body>
  </div>
<br /><br />
<div class="execute">Click me 2</div>
 </body>
 </html>  

but if i merge it in another code it highlights and as invalid code. what does it means?

Upvotes: 1

Views: 165

Answers (4)

Mark
Mark

Reputation: 6864

Ther are several code issues. double <head> tags, HTML elements after the <body> tag.

cleaned up code:

<html>
 <head>
 <style>
  .execute { background-color: red; height: 25px; }
 </style>
  <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js"></script>
  <script>
  dojo.ready(function() { // Dojo will run this after being initialized
    // Get A list of all tags with id execute and add a event onClick
    dojo.query(".execute").connect("onclick", function(evt) {
      alert("Event triggered!");
      // ...
    });
  });
  </script>
</head>
 <body>
  <div class="execute">Click me 1</div>
  <br><br>
  <div class="execute">Click me 2</div>
 </body>
</html>

Upvotes: 2

Mark Beleski
Mark Beleski

Reputation: 55

The structure of an HTML page should be as follow:

<html>
<head>
<title></title>
</head>
<body>
</body>
</html>

Although they do not have to be, most people put script tags within the opening and closing header tags. For example:

<html>
<head>
<title></title>
<script>

<!--This is where all your functions should be.-->

</script>
</head>
<body>
</body>
</html>

Upvotes: 1

Grant Thomas
Grant Thomas

Reputation: 45068

<head> should only appear once, directly under the <html>, and not within <body>.

Exceptions to this are iframes embedded within existing pages, which have their own document structure.

Upvotes: 1

tckmn
tckmn

Reputation: 59343

Just remove the second <head>.

Why do you have two heads? <script>s don't have to be in <head>s.

You should only have a single <head> in your document.

Upvotes: 1

Related Questions