2

Possible Duplicate:
Why don’t self-closing script tags work?

I know, this is a very basic question. But I admit I don't know an answer for this. I'm trying to include external js file in my html. Here are the two cases.

<script src="jquery-1_9_0.js"></script><!-- its working -->

<script src="jquery-1_9_0.js"/><!-- not working -->

Why is it so? where as for html input it works in both cases

<input type="text" value="enter value"/><!-- works -->
<input type="text" value="enter value"></input><!-- Also works -->

Can I know the reason?

Community
  • 1
  • 1
srk
  • 4,857
  • 12
  • 65
  • 109
  • it's because of specifications (I'm too lazy to link/find information on it, someone will probably help you with that), so basicly some tags need closing tags, while others don't. the script tag is one of those tags that need a closing tag. – kennypu Feb 01 '13 at 07:04

1 Answers1

3

From XHTML 1 specification

C.3. Element Minimization and Empty Element Content

Given an empty instance of an element whose content model is not EMPTY 
(for example, an empty title or paragraph) do not use the minimized 
form (e.g. use <p> </p> and not <p />).

And from XHTML 1 DTD (strict)

<!ELEMENT script (#PCDATA)>
<!ELEMENT textarea (#PCDATA)>
<!ELEMENT hr EMPTY>
<!ELEMENT br EMPTY>

This means that an element that is not specified as EMPTY cannot be self-closing. You can write <hr/> or <br/>, but you cannot write <script /> or <textarea />. Think them as a container for their content. A container cannot be self-closing.

pbaris
  • 4,525
  • 5
  • 37
  • 61