How to get next and previous sibling elements and inner text?
To get next and previous sibling and its inner text we can use nextElementSibling and previousElementSibling property in Javascript, nextElementSibling returns the next element (not text and comment nodes) and previousElementSibling returns the previous element (not text and comment nodes).
<ul id="parentEl">
<li id="item1">Javascript (first item)</li>
<li id="item2">jQuery (second item)</li>
</ul>
//Example 1: You can get next and pervious element ( li#item1 and li#item2 )
<script>
const nxtSibling = document.getElementById("item1").nextElementSibling;
const prvSibling = document.getElementById("item2").previousElementSibling;
console.log(nxtSibling);
console.log(prvSibling);
</script>
//Example 2: You can get next and pervious text ( Javascript (first item) and jQuery (second item) )
<script>
const nxtSibling = document.getElementById("item1").nextElementSibling.innerHTML;
const prvSibling = document.getElementById("item2").previousElementSibling.innerHTML;
console.log(nxtSibling);
console.log(prvSibling);
</script>