GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes empty tags 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 "empty tags" Watch "empty tags" New topic
Author

empty tags

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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 ?


[My Blog]
All roads lead to JavaRanch
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Did you put a space before the slash? It is required in some browsers
ie <do this /> <not this/>
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

No I did not put any space.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

have you tried it with a space?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
because a div is not supposed to be an empty tag.

Eric
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
validate the code on the w3 validator.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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
 
GeeCON Prague 2014
 
subject: empty tags