Welcome to WebmasterWorld Guest from 54.224.57.95

Forum Moderators: incrediBILL

Message Too Old, No Replies

Adding ID attribute to HTML tag

     
11:33 pm on Jul 9, 2012 (gmt 0)

10+ Year Member



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?
12:02 pm on Jul 10, 2012 (gmt 0)

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



something like this might work:

var html=document.getElementsByTagName("HTML")[0];
html.setAttribute("id", "xyz");
12:12 pm on Jul 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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>
1:17 pm on Jul 10, 2012 (gmt 0)

10+ Year Member



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?
1:48 pm on Jul 10, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



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.
1:12 am on Jul 11, 2012 (gmt 0)

10+ Year Member



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.
5:15 am on Jul 11, 2012 (gmt 0)

10+ Year Member



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.
1:34 pm on Jul 11, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



What kind of plugin is this?
4:16 pm on Jul 11, 2012 (gmt 0)

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



I imagine you know that half-doctype puts the document into Quirks mode. Be ready for other oddities in various browsers. :-)
5:53 pm on Jul 11, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Right, what rocknbil said. You're just asking for even worse problems by running in Quirks mode.
11:46 pm on Jul 11, 2012 (gmt 0)

10+ Year Member



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.
11:58 pm on Jul 11, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Do you have a more complete example of what you're trying to do? Perhaps moving this conversation to the JavaScript forum?
4:32 pm on Jul 12, 2012 (gmt 0)

10+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month