Getting the parent group id of Element

Hi
I have an element in a group. The group has an id and I wanted to use Javascript to be able to get the id of group from the containing element.

To be honest a little more info would help. but here is an answer on assumption that you mean

HYPE_element_container

There are a few ways this can be done… here is one.

//HYPE_element_container
	var _containers = hypeDocument.getElementById(hypeDocument.documentId()).querySelectorAll('.HYPE_element_container')
	 

for (i = 0; i < _containers.length; i++) { 
 var _children = _containers[i].childNodes 
  
			for (i = 0; i < _children.length; i++) { 
 					console.log(_children[i].id );
				} 
		}

Thanks for that.
Yes I did mean grouping of elements in the list view of elements which I guess is HYPE_element_container.
I was trying to avoid having to go through all the elements every time I need to check for this,

A bit more info on what your goal is and what you know at the time of trying to access the group id may help in a better answer.

maybe an example project to help explain the set up and goal…

I have attached a sample project. Tapping on any of the red buttons I would want to know what group they belong to.
ParentGroup.hype.zip (25.3 KB)

one of the simplest ways I think is

console.log( element.parentElement.parentElement.id)

The buttons are in a container (DIV) each inside the group.

This is why we use parentElement twice.

As illustrated with this version.

console.log(element.closest(".HYPE_element_container").closest(".HYPE_element").id)

1 Like