soup icon indicating copy to clipboard operation
soup copied to clipboard

Navigating to Parent

Open joekinley opened this issue 5 years ago • 2 comments

In order for proper selection it would be awesome to be able to navigate to the current elements Parent, then keep going through siblings and all.

Right now it is quite hard to properly find what I am looking for from a strict top-down view.

joekinley avatar Sep 28 '20 15:09 joekinley

Good idea. Will add something along the lines of Root.Parent to access the parent element

anaskhan96 avatar Sep 28 '20 16:09 anaskhan96

I make a function you can review it if it is ok you can add to your code

func (r Root) FindParent(tagName string) Root {
	parent := r.Pointer.Parent
	if parent == nil {
		return Root{Pointer: parent}
	}
	rParent := Root{Pointer: parent, NodeValue: parent.Data}
	if strings.ToLower(parent.Data) == strings.ToLower(tagName) {
		return rParent
	}
	return rParent.FindParent(tagName)
}

sijms avatar Apr 18 '22 15:04 sijms