Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why self closing script tag is not working ?

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer: not all browsers support the notation so you can not use it
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah; you have to use </script> to make sure it'll work across browsers.

Yay, browsers.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do it in XHTML either.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And XHTML is dead

Eric
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You gotta love the simplicity of the HTML 5 DOCTYPE:


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You gotta love the simplicity of the HTML 5 DOCTYPE:



Wow !! and thanks for the information..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic