1

Topic: DOM. Why after last child "element" cannot be the text?

I read the textbook. There such question

http://learn.javascript.ru/traversing-dom wrote:

If elem is the arbitrary node DOM ...
Whether it is true, what elem.lastChild.nextSibling always null?
Whether it is true, what elem.children [0].previousSibling always null?

And such answer:

http://learn.javascript.ru/traversing-dom wrote:

Yes, truly, with a stipulation. The element elem.lastChild last, at it is not present the right neighbor.
Stipulation: elem.lastChild.nextSibling produces an error if elem has no children.
No, incorrectly, it can be a text node. Value elem.children [0] is the first node-element, before it there can be a text.
To similarly previous case if at elem there are no children-elements - there will be an error.

I did not understand something than both these situations differ.

http://learn.javascript.ru/traversing-dom wrote:

Properties firstChild and lastChild provide rapid access to the first and last element.

Why after the last element there can not be a text in that case?

2

Re: DOM. Why after last child "element" cannot be the text?

questioner wrote:

why after the last element there can not be a text in that case?

In which case?
Case name a certain example of a marking. You did not result a marking example...

3

Re: DOM. Why after last child "element" cannot be the text?

questioner wrote:

why after the last element there can not be a text in that case?

Consider that the text in DOM - the same element, it is simple without a tag name, I think the author of your example says that if took last - that after it anything is not present. (Sorri for a pun)

4

Re: DOM. Why after last child "element" cannot be the text?

questioner , here a certain illustration of a certain situation

<! DOCTYPE html>
<html>
<head>
<meta http-equiv ='Content-Type ' content ='text/html; charset=windows-1251 '/>
<! -
<script src ='http://code.jquery.com/jquery-latest.js '> </script>
<script src = "https://code.angularjs.org/1.3.9/angular.min.js"> </script>
<script src = "https://code.angularjs.org/1.3.9/angular-route.js"> </script>
-->
<style type ='text/css'>
</style>
<script type ='text/javascript '>
</script>
</head>
<body>
<ul>
<li> Item 0 </li>
<li> Item 1 </li>
<li> Item 2 </li>
</ul>
<script type ='text/javascript '>
var o=document.querySelector (' ul ');
alert (o.firstChild.previousSibling);
alert (o.children [0].previousSibling);
alert (o.lastChild.nextSibling);
alert (o.children [o.children.length-1].previousSibling);
</script>
</body>
</html>

I.e. there is a difference with what to work, with an array cell of children or with properties "the first" and "last" child...

5

Re: DOM. Why after last child "element" cannot be the text?

krvsa wrote:

it is passed...
In which case?
Case name a certain example of a marking. You did not result a marking example...

I gave the reference. The marking can be any.

6

Re: DOM. Why after last child "element" cannot be the text?

mage.lan wrote:

it is passed...
Consider that the text in DOM - the same element, it is simple without a tag name, I think the author of your example says that if took last - that after it anything is not present. (Sorri for a pun)

And why before the first still something can be?

7

Re: DOM. Why after last child "element" cannot be the text?

krvsa wrote:

questioner , here a certain illustration of a certain situation

<! DOCTYPE html>
<html>
<head>
<meta http-equiv ='Content-Type ' content ='text/html; charset=windows-1251 '/>
<! -
<script src ='http://code.jquery.com/jquery-latest.js '> </script>
<script src = "https://code.angularjs.org/1.3.9/angular.min.js"> </script>
<script src = "https://code.angularjs.org/1.3.9/angular-route.js"> </script>
-->
<style type ='text/css'>
</style>
<script type ='text/javascript '>
</script>
</head>
<body>
<ul>
<li> Item 0 </li>
<li> Item 1 </li>
<li> Item 2 </li>
</ul>
<script type ='text/javascript '>
var o=document.querySelector (' ul ');
alert (o.firstChild.previousSibling);
alert (o.children [0].previousSibling);
alert (o.lastChild.nextSibling);
alert (o.children [o.children.length-1].previousSibling);
</script>
</body>
</html>

I.e. there is a difference with what to work, with an array cell of children or with properties "the first" and "last" child...

8

Re: DOM. Why after last child "element" cannot be the text?

krvsa;
Can all the same in last

alert (o.children [o.children.length-1].nextSibling);

9

Re: DOM. Why after last child "element" cannot be the text?

questioner wrote:

can all the same in last

Also what there? smile))
an element in an array of children. After it there is a text...

10

Re: DOM. Why after last child "element" cannot be the text?

questioner;
here the answer to your question
As usual -  programmers,  browsers.

11

Re: DOM. Why after last child "element" cannot be the text?

mage.lan wrote:

questioner;
here the answer to your question
As usual -  programmers,  browsers.

In what  can explain?
I here see  transfer in which mix concepts of elements and nodes. Well so it is necessary to read transfers.

12

Re: DOM. Why after last child "element" cannot be the text?

Alexander A. Sak wrote:

In what  can explain?

In a gap which is before the first element. Generally DOM and its methods - one continuous disgrace. As though the woman invented.

13

Re: DOM. Why after last child "element" cannot be the text?

mage.lan wrote:

it is passed...
In a gap which is before the first element. Generally DOM and its methods - one continuous disgrace. As though the woman invented.

Did not understand. Authors of the browser  because the author of page delivered a gap before the first element?

14

Re: DOM. Why after last child "element" cannot be the text?

mage.lan wrote:

  programmers,  browsers.

mage.lan wrote:

Generally DOM and its methods - one continuous disgrace. As though the woman invented.

And I  ` Artanjan! (
I.e. anything new... smile))

15

Re: DOM. Why after last child "element" cannot be the text?

Alexander A. Sak wrote:

did not understand. Authors of the browser  because the author of page delivered a gap before the first element?

The browser interposes a gap before the first element, instead of the author.

krvsa wrote:

And I  ` Artanjan! ()
I.e. anything new... smile))

The bad morning?
I and itself  sometimes. All  it do, simply one consider themselves as gods, and simply pots mold others.

16

Re: DOM. Why after last child "element" cannot be the text?

mage.lan wrote:

it is passed...
The browser interposes a gap before the first element, instead of the author.

Can give an example? In my pattern of the world so:
With such marking before the first <li> there is a text node. That we began to name "a gap before the first element".

<ul>
<li> First </li>
<li> Second </li>
</li>

With such marking before the first <li> the text node is not present.

<ul> <li> First </li>
<li> Second </li>
</li>

Your way, we should find out in the second variant a gap (a text node) before the first <li>?

17

Re: DOM. Why after last child "element" cannot be the text?

Alexander A. Sak;
In my pattern of the world, in a marking

<ul>
<li>
...

There are no gaps between tags ul and li

18

Re: DOM. Why after last child "element" cannot be the text?

mage.lan wrote:

in my pattern of the world, in a marking

<ul>
<li>
...

There are no gaps between tags ul and li

And it there is! smile))

<ul>
<li> <li>
</ul>
<script type ='text/javascript '>
var o=document.getElementsByTagName (' ul ');
alert (o [0].children [0].previousSibling);
</script>

19

Re: DOM. Why after last child "element" cannot be the text?

krvsa;
?
Nobody reads that-whether...
For this reason I also told .
At handling XML all parcers should speak deliberately preserve space if it is necessary that command gaps got to handling.
The HOUSE went the "" a way. The relation to gaps at HOUSE functions - disgusting they them see, .

20

Re: DOM. Why after last child "element" cannot be the text?

mage.lan wrote:

For this reason I also told .

It only in your head...