homepage Welcome to WebmasterWorld Guest from 184.73.104.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    
Adding ID attribute to HTML tag
Kendo

5+ Year Member



 
Msg#: 4473946 posted 11:33 pm on Jul 9, 2012 (gmt 0)

I have a web page that is throwing errors due to the DOCTYPE statement negating its presence. HTML5 doesn't like this tag either. The ID is needed by a JavaScript and without it we get errors and code failure. This is the tag that we need...

<HTML id="xyz">

I think that I read or dreamed somewhere that an alternative might be to use JavaScript to declare this ID, but how?

 

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 4473946 posted 12:02 pm on Jul 10, 2012 (gmt 0)

something like this might work:

var html=document.getElementsByTagName("HTML")[0];
html.setAttribute("id", "xyz");

mattur

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4473946 posted 12:12 pm on Jul 10, 2012 (gmt 0)

HTML5 allows the id attribute to be set on the <html> element, HTML4 didn't (but this rule doesn't affect parsing in browsers). So this is valid HTML5 code:


<!DOCTYPE html>
<HTML id="xyz">
<head>
<title></title>
</head>
<body>
<p></p>
</body>
</html>

Kendo

5+ Year Member



 
Msg#: 4473946 posted 1:17 pm on Jul 10, 2012 (gmt 0)

HTML5 allows the id attribute to be set on the <html> element


When I tested HTML5 and got an error about the ID not being defined in the JavaScript, I posted here. I'll try the JS method and hope that works.

But with JS, because it actions in the client browser, and because it runs between the head tags, wouldn't the opportunity to modify the html tag already have gone?

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4473946 posted 1:48 pm on Jul 10, 2012 (gmt 0)

Don't use JavaScript for this unless it's something that's totally just a progressive enhancement. There's really no need for JavaScript in this example. The example that mattur posted is perfectly valid HTML5, with the id attribute defined in the markup as it should be.

Kendo

5+ Year Member



 
Msg#: 4473946 posted 1:12 am on Jul 11, 2012 (gmt 0)

Unfortunately the JavaScript on the page is crucial and it's failing to read that ID when it's hard coded while using the html5 tag and some other doctype tags.

Kendo

5+ Year Member



 
Msg#: 4473946 posted 5:15 am on Jul 11, 2012 (gmt 0)

After some more testing I found that the problem is not the method. Writing in the ID with JavaScript works just as well as hard coding the ID. The real problem is that HTML5 and some other DOCTYPE statements are killing the interaction between JavaScript and the browser plugin. All the JS is trying to do is get a signal from the plugin to say that it's completed loading. Otherwise that handshake works in all web browsers (except Chrome) by simply using...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

without the usual "http://www.w3.org/TR/html4/loose.dtd" included.

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4473946 posted 1:34 pm on Jul 11, 2012 (gmt 0)

What kind of plugin is this?

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4473946 posted 4:16 pm on Jul 11, 2012 (gmt 0)

I imagine you know that half-doctype puts the document into Quirks mode. Be ready for other oddities in various browsers. :-)

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4473946 posted 5:53 pm on Jul 11, 2012 (gmt 0)

Right, what rocknbil said. You're just asking for even worse problems by running in Quirks mode.

Kendo

5+ Year Member



 
Msg#: 4473946 posted 11:46 pm on Jul 11, 2012 (gmt 0)

After further testing I now find that whereas the success of our handshake was dependent on doctype, the problem gets worse... browsers have become too unreliable. Before you could compensate for irregularities and those updates would be good for a couple of years. Now there is a danger of losing support within a month.

IE version is unlikely to change, but with Fool and Clown one could run a pool on guessing their version number available at the end of the year and there will not be many winners.

Fotiman

WebmasterWorld Senior Member fotiman us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4473946 posted 11:58 pm on Jul 11, 2012 (gmt 0)

Do you have a more complete example of what you're trying to do? Perhaps moving this conversation to the JavaScript forum?

Kendo

5+ Year Member



 
Msg#: 4473946 posted 4:32 pm on Jul 12, 2012 (gmt 0)

No. It's a proprietary plugin that is needed to demonstrate the issue, and demonstration requires licensing. Anyway, we are dropping that support feature as it won't be needed by the time our team releases an alternative product.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved