Next Right Sibling
2022年5月1日小于 1 分钟
Next Right Sibling
Question
Given a DOM tree and a target element, please return the next right sibling.
Like above, the next right sibling of <button/>
is the blue <a/>
. Notice that they don't necessarily have the same parent element.
If no right sibling, then return null
.
What is time & space cost of your solution ?
Code
/**
* @param {HTMLElement} root
* @param {HTMLElement} target
* @return {HTMLElemnt | null}
*/
function nextRightSibling(root, target) {
// your code here
}