Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

empty tags

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just figured out that empty tags are not working when playing with DOM.
For example :
<div .... />
<input...>

With the DOM inspector, I've realized that input was inside div !!
Instead, I had to write :
<div .... ></div>
<input...>

Why is this so ? Do I have to set something to be able to use empty tags ?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you put a space before the slash? It is required in some browsers
ie <do this /> <not this/>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No I did not put any space.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you tried it with a space?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because a div is not supposed to be an empty tag.

Eric
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
validate the code on the w3 validator.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to a strict XML interpretation, <div/> should mean the same thing as <div></div>.

But the browsers are notorious for following their own rules.

Bottom line, use <div></div>.

P.S. Don't try that with the script tag either.
[ September 01, 2006: Message edited by: Bear Bibeault ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all. From now on, I'll avoid using empty tags.

P.S. Don't try that with the script tag either.

Actually, that's also why I asked I've wasted half an hour trying to figure out why my script was not being called
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic