Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigating to Parent #63

Open
joekinley opened this issue Sep 28, 2020 · 2 comments
Open

Navigating to Parent #63

joekinley opened this issue Sep 28, 2020 · 2 comments

Comments

@joekinley
Copy link

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.

@anaskhan96
Copy link
Owner

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

@sijms
Copy link

sijms commented Apr 18, 2022

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants