[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Element output in JavaScript consoles

ram

12/14/2015 3:54:00 PM

I was looking for some DOM applications as examples for my
JavaScript course and came up with this use of the Firefox
console (input/output pairs):

document.firstElementChild
<html>

document.firstElementChild.firstElementChild
<head>

document.firstElementChild.firstElementChild.firstElementChild
<meta charset="UTF-8">

document.firstElementChild.firstElementChild.firstElementChild.firstElementChild
null

I see that the Firefox console kinda »pretty prints« the
element. I.e., it does not just say

[object]

but

<html>

. I like this! But can I rely on it?

Is this output experimental or is it an established feature?

Can it be expected to remain this way in the future?

Do other browser consoles behave similar?

6 Answers

Steve Willner

7/9/2014 9:36:00 PM

0

On 2014-06-27 6:49 PM, Mark Brader wrote:
> Well, he could have applied Law 64B7, which specifies that if both
> sides revoke on the board then the table result stands.

No, L64B7 says there are no _rectification_ tricks. L64C still applies,
though.

> You were applying for a judgement under Law 64C

Right.

> which is at the director's discretion

Not exactly. It's a judgment ruling whether penalty tricks compensate
for the revoke's damage or not, but once that judgment is made, giving
an adjusted score or not is automatic. It can be a split score and can
be weighted in some jurisdictions.

I didn't bother to follow the exact sequence of events after the revoke,
but L64C and three tricks to the defense seem automatic.

--
Help keep our newsgroup healthy; please don't feed the trolls.
Steve Willner Phone 617-495-7123 swillner@nhcc.net
Cambridge, MA 02138 USA

ram

12/14/2015 4:57:00 PM

0

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>document.firstElementChild
><html>

Ok, my preceding question has become less important
to me, because I now believe that for the first examples
a member with a primitive type is better, so I now use

document.nodeType

.

Martin Honnen

12/14/2015 5:04:00 PM

0

Stefan Ram wrote:
> I was looking for some DOM applications as examples for my
> JavaScript course and came up with this use of the Firefox
> console (input/output pairs):
>
> document.firstElementChild
> <html>

> I see that the Firefox console kinda »pretty prints« the
> element. I.e., it does not just say
>
> [object]
>
> but
>
> <html>
>
> . I like this! But can I rely on it?

> Do other browser consoles behave similar?

Chrome outputs an expandable DOM tree representation of the element
node, Edge does it similar to Chrome.

RobG

12/19/2015 6:05:00 AM

0

On 15/12/2015 01:53, Stefan Ram wrote:
> I was looking for some DOM applications as examples for my
> JavaScript course and came up with this use of the Firefox
> console (input/output pairs):
>
> document.firstElementChild
> <html>

[...]

>
> I see that the Firefox console kinda »pretty prints« the
> element. I.e., it does not just say
>
> [object]
>
> but
>
> <html>
>
> . I like this! But can I rely on it?

As in "do other browsers do it the same way", then no. Nor is it
standardised. Even Firefox may change its behaviour any time the
developers want (i.e. it is implementation dependent).


> Is this output experimental or is it an established feature?

It is an established feature in reasonably modern browsers.


> Can it be expected to remain this way in the future?

No, see above.


> Do other browser consoles behave similar?

"Similar" in that they tend to print something more useful than
"object", but not consistently the same format and certainly not content.


--
Rob

JR

12/19/2015 12:55:00 PM

0

On 12/14/2015 02:57 PM, Stefan Ram wrote:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>> document.firstElementChild
>> <html>
>
> Ok, my preceding question has become less important
> to me, because I now believe that for the first examples
> a member with a primitive type is better, so I now use
>
> document.nodeType
>

node.firstElementChild is well supported by modern browsers [1], but it
only returns the first child that is an element (nodeType = 1), and null
otherwise. [1]

[1] <http://www.quirksmode.org/dom/w3c_traversa...
[2] <http://www.w3.org/TR/ElementTraversal/#attribute-firstElemen...



--
Joao Rodrigues

JR

12/19/2015 3:11:00 PM

0

On 12/19/2015 10:55 AM, Joao Rodrigues wrote:
> On 12/14/2015 02:57 PM, Stefan Ram wrote:
>> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>> document.firstElementChild
>>> <html>
>>
>> Ok, my preceding question has become less important
>> to me, because I now believe that for the first examples
>> a member with a primitive type is better, so I now use
>>
>> document.nodeType
>>
>
> node.firstElementChild is well supported by modern browsers [1], but it
> only returns the first child that is an element (nodeType = 1), and null
> otherwise. [1]
^^^
meant [2]

>
> [1] <http://www.quirksmode.org/dom/w3c_traversa...
> [2] <http://www.w3.org/TR/ElementTraversal/#attribute-firstElemen...
>
>

You may try this in console (FF, Chrome):

var all = document.querySelectorAll('*');
[].forEach.call(all,
item => {
var ret = item.firstElementChild;
if (ret) console.log(ret);
}
);


--
Joao Rodrigues