Skip to content

Slick throws when feature testing XHTML document #74

@nwellnhof

Description

@nwellnhof

The feature detection code in Slick.Finder throws an exception with XHTML documents in Firefox and Chrome. I think this used to work with earlier versions of these browsers, but I'm not sure. Example:

var parser = new DOMParser();
var xml = parser.parseFromString('<html xmlns="http://www.w3.org/1999/xhtml"><body></body></html>', 'text/xml');
xml.documentElement.getElement('body');

Results in TypeError: testNode.style is undefined in Firefox, Uncaught TypeError: Cannot set property 'display' of null in Chrome.

JSFiddle: http://jsfiddle.net/4UFHV/

The exception is thrown at line 89 in Slick.Finder.js.

Reason: The test node is created with an empty namespace. Subsequently, the innerHTML and getElementsById tests succeed, the document is detected as HTML, but setting a style on the newly created element fails.

Possible solution: Create the test node using createElementNS:

var testNode = document.createElementNS('http://www.w3.org/1999/xhtml', 'div');

This works for XHTML documents but it might break other HTML documents.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions