aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Why self closing script tag is not working ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Why self closing script tag is not working ?" Watch "Why self closing script tag is not working ?" New topic
Author

Why self closing script tag is not working ?

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Hi all,

I'm trying a jquery example, I tried this simple code:


If I self closed the tag, like I shown in the code <script .../>, then browser doesn't render the below written script of "hello World", but If I closed the script tag in XHTML fashion, like


Why this behavior ? Although both ways are valid HTML closing tag notion.. Am I correct or I'm missing something silly ??


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Answer: not all browsers support the notation so you can not use it
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yeah; you have to use </script> to make sure it'll work across browsers.

Yay, browsers.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

This is also true of many other tags that can have content. In general, you cannot self-close tags that can also be written with content.

Remember, despite its similarities, HTML is not XML.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Thanks a ton for the replies. I think, for the same "browser-compatibility" issue, XHTML is a new way to markup the hyper text language !!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

You can't do it in XHTML either.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
And XHTML is dead

Eric
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Eric Pascarello wrote:And XHTML is dead

&
Interesting and the same time disappointing too.
I thought XHTML is the new way to format HTML, which took care of those weird things happen when content tags are self closed.

Then, obvious question arise if not HTML nor XHTML, then what it is ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

HTML 5 will allow you to write your markup as either lenient HTML or well-formed XHTML, without being XHTML, which was a dead end.

So it will give all the advantages of well-formed markup, without the headaches of XHTML.

There are a lot of interesting blogs and articles on the web regarding HTML 5. They're worth searching out.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

hmm, so many things to learn, HTML 5, XHTML, DHTML, MHTML. I feel like I don't know anything...
I check my pages DTD, I'm still coding in HTML4.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

You gotta love the simplicity of the HTML 5 DOCTYPE:


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61623
    
  67

Sagar Rohankar wrote:hmm, so many things to learn, HTML 5, XHTML, DHTML, MHTML.

Well, XHTML is dead so there's no need to bother with it unless you have a business need to do so. Just learn how to write well-formed HTML and reap all the benefits.

There really isn't any such thing as "DHTML". That's just an antiquated term for using JavaScript, CSS and HTML to create dynamic client-side pages.

And MHTML, which frankly I had never even heard of, isn't supported by much and so isn't important at all , again unless you have a specific business need.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Bear Bibeault wrote:You gotta love the simplicity of the HTML 5 DOCTYPE:



Wow !! and thanks for the information..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why self closing script tag is not working ?