The example in this article describes the Prev and next method of the JavaScript implementation to obtain the neighboring sibling nodes of an element. Share to everyone for your reference, specific as follows:
/**
* Gets the adjacent element
* @param ele reference element
* @param type, the last (1) or next (0)
* @return Returns the found element Dom object, NONE returns null
* *.
function Getnearele (ele, type) {
type = = Type = 1? "PreviousSibling": "NextSibling";
var nearele = Ele[type];
while (Nearele) {
if (Nearele.nodetype = = 1) {return
nearele;
}
Nearele = Nearele[type];
if (!nearele) {break
;
}
}
return null;
}
/**
* Gets the last element of the current executing object
/function prev () {return
Getnearele (this, 1);
}
/**
* Gets the next element of the current executing object/
function next () {return
Getnearele (this, 0);
}
var ele = document.getElementById ("xxx");
var prevelement = Prev.call (ele);
var nextelement = Next.call (ele);
For more information on JavaScript node operations interested readers can view the site topics: "JavaScript Operation DOM Skills Summary"
I hope this article will help you with JavaScript programming.