Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   дочерние элементы и их поиск (https://javascript.ru/forum/misc/17929-dochernie-ehlementy-i-ikh-poisk.html)

bot87 09.06.2011 11:43

дочерние элементы и их поиск
 
Всем привет!!
приведите плиз очень прошу и умоляю кросс использование для получение lastChild s firstChild ,previousSibling:(

NoResponse 09.06.2011 12:05

а что именно не получается то ?

nikita.mmf 10.06.2011 16:38

function getChildren( elem ){
   var child = elem.firstChild, res = [];
   while ( child ) {
      if ( child.nodeType == 1 ) {
          res [ res.length ] = child;
      }
      child = child.nextSibling;
   }
   return res;
}
var childrenNode = getChildren( node );
var firstChild = childrenNode.length ? childrenNode[0] : null;
var lastChild = childrenNode.length ? childrenNode[res.length - 1] : null;


Часовой пояс GMT +3, время: 00:05.