How to validate custom attributes of HTML elements in W3C validator?

Sometimes you need to use (X)HTML element attributes that are not part of any W3C standard doctypes. Or you may want to use strict version of doctype with some attributes that are only in transitional version of doctype. Well, it certainly has its reasons (I will mention it) why they were removed and if you would like to use strict doctype then you shouldn’t use them.

Most of the time, you can follow this rule. In fact, you should use strict doctype instead of transitional doctype where possible. In strict versions of doctypes presentation attributes are removed and are expected to be replaced with CSS properties. I prefer strict doctypes. Apart from other things modern browsers use their most standards compliant rendering mode and therefore it is easier to make appearance of the site look exactly the same in various browsers. (commonly spaces between elements may be problematic)

Read more

Inner/Outer XHTML – or how to get truly original source of element in JavaScript?

There are some ways to get the original source of any HTML element in JavaScript. And they work fine in most situations. However, there are situations where these ways are not really sufficient and I especially mean not cross-browser enough.

innerHTML property is probably the most frequently used method, but it has some well-known drawbacks. First of all, innerHTML property does not contain (X)HTML written by original author of (X)HTML page. Instead, it contains some sort of browser specific Document Object Model string representation. Especially in IE this representation is quite ugly (missing quotes, capital letters of tags, …). And thus we encounter another problem – content of innerHTML property differs in different browsers!

But why is this important that it differs? Should we care? Maybe, we should. There might be situations when we may need the same value of innerHTML property for all browsers. There are always some tricks to get around this need and make it in other way, or simply make different solutions for different browsers. But wouldn’t it be nice to have function that not only returns same content in all modern major browsers, but moreover returns exactly the content that was created by author of webpage? Getting truly original source code is in fact another thing that might be sometimes useful.

Read more