Firstchild,lastchild,nextsibling,previoussibling is supported under IE
But under FF, because it will be the space between the labels as a text node, so in order to accurately find the corresponding elements, will be used
Firstelementchild,
Lastelementchild,
Nextelementsibling,
Previouselementsibling
Compatible notation is like this
var Ofirst = oparent.firstelementchild| | Oparent.firstchild
You can write it like that.
var ofirst = oparent.children[0];
var olast = oparent.lastelementchild| | Oparent.lastchild
You can write it like that.
var olast = oparent.children[oparent.children.length-1];
var onext = Obj.nextelementsibling| | Obj.nextsibling
var opre = Obj.previouselementsibling| | Obj.previoussibling
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title><Script>window.onload= function() { varOul=document.getElementById ('UL1'); /*element. LastChild | | element. Lastelementchild the first child node element. LastChild | | element. Lastelementchild the last child node element. Nextsi Bling | | Element. Nextelementsibling the next sibling node element. previoussibling | | element. previouselementsibling Previous Sibling node*/ varOfirst=Oul.firstelementchild||Oul.firstchild; //var ofirst = oul.children[0];OFirst.style.background= 'Red'; varOlast=Oul.lastelementchild||Oul.lastchild; //var olast = oul.children[oul.children.length-1];OLast.style.background= 'Yellow'; varOnext=ofirst.nextelementsibling||ofirst.nextsibling; ONext.style.background= 'Blue'; varOprev=olast.previouselementsibling||olast.previoussibling; OPrev.style.background= 'Orange'; }</Script></Head><Body><ulID= "UL1"> <Li>11111</Li> <Li>22222</Li> <Li>33333</Li> <Li>44444</Li> </ul></Body></HTML>
Compatible firstchild,lastchild,nextsibling,previoussibling notation