On Wed, Jun 1, 2011 at 3:10 AM, RobG <[email protected]> wrote:
>
>
> On May 29, 6:42 pm, Diego Perini <[email protected]> wrote:
>> Nathan,
>> the "querySelectorAll" method exists also on IE 8 in Standard Mode.
>>
>> In all IE versions < 9 there are problem with the "Universal selector"
>> since their API methods returns text nodes included in the result set.
>> This is not only a problem with "querySelectorAll", in fact on IE < 9
>> also "getElementsByTagName" has the same problems with text nodes.
>>
>> There are several other bugs in IE < 9 related to elements selection
>> API. The baseline for IE is that after retrieving the NodeList one
>> need to go through it members discarding text nodes, comments and
>> invalid elements.
>>
>> The conditional I prefer to use to filter appropriate nodes from the list is:
>>
>>     if (element.nodeName > '@') {
>>       .... // it is an Element node
>
> That makes an assumption that all nodes with a nodeNames starting with
> a character after @ are elements (or at least are nodes implementing
> interface Element). However, the above will include nodes that
> implement interfaces DocumentType, Entity, EntityReference, Notation
> and ProcessingInstruction.
>

None of the node types you listed above should ever be in a NodeList
produced by querySelectorAll. Though on IE <= 8 comments are included.

The kind of list I suggested to filter with that "non-standard" way of
checking is a NodeList, but will do for an HTMLCollection returned by
gEBTN.

And on IE a "DocumentType" node (probably the only one likely to be
found in HTML documents) produces "#comment" as node name.

> Is that what you want?
>
>>     }
>>
>> also the standard one is:
>>
>>     if (element.nodeType == 1) {
>>       .... // it is an Element node
>>     }
>
> If the intention is to filter for elements, then a test that explicity
> tests for elements is prefereable to one that doesn't.
>
>

Yes the standard way that I purposely cited is the correct way of doing it.

>> I prefer the first since it also helps discard fake "closed tags"
>> elements for non recognized HTML5 elements, for example:
>>
>>     <abbr>NYC</abbr>
>>
>> could be recognized as two elements in some IE version <= 8, the first
>> is the open tag "abbr", the second is the close tag "/abbr" which
>> tagName/nodeName starts with a slash.
>
> ABBR nodes are dysfunctional in IE < 7 and require special treatment.
> Simply discarding the closing tag "element" is only part of the job.
>

Catching those false element nodes and distinguish them from real
elements is the first thing to do. Any remaining job becomes easier.

--
Diego

>
> --
> Rob
>
> --
> To view archived discussions from the original JSMentors Mailman list: 
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here: 
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to