JavaScript is used to obtain the prev and next methods of an element adjacent to a sibling node.
This example describes how to use JavaScript to obtain the prev and next methods of an element's adjacent sibling nodes. We will share this with you for your reference. The details are as follows:
/*** Obtain the adjacent element * @ param ele reference object element * @ param type, the previous one (1) or the next one (0) * @ return returns the searched element Dom object. If none, null is returned */function getNearEle (ele, type) {type = 1? "Previussibling": "nextSibling"; var nearEle = ele [type]; while (nearEle) {if (nearEle. nodeType = 1) {return nearEle;} nearEle = nearEle [type]; if (! NearEle) {break;} return null;}/*** get the previous element of the current execution object */function prev () {return getNearEle (this, 1 );} /*** get the next element of the current execution object */function next () {return getNearEle (this, 0);} // var ele = document. getElementById ("xxx"); // var prevElement = prev. call (ele); // var nextElement = next. call (ele );