HTML Elements Forums Navigation Accordion getting data element from accordion smart-accordion-item

This topic contains 2 replies, has 2 voices, and was last updated by Avatar edwardsmarkf 5 months, 3 weeks ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #100774
    Avatar
    edwardsmarkf
    Participant

    hello – it appears as if using accordion is going to meet our needs perfectly if i can get past this issue.

    i need to be able to accessĀ data from the smart-accordion-item when an item is clicked:

    https://codepen.io/edwardsmarkf/pen/XWXreve?editors=1111

    or perhaps there is there a better way to do this?

    usingĀ this.parentElementĀ andĀ this.parentNodeĀ does not appear to work for me.

    our smart element will contain thousands of accordion items, each with up to ten clickable items.Ā  we need to keep the html as small as possible.

    #100775
    Avatar
    Hristofor
    Participant

    Hi edwardsmarkf,

    You can get the AccordionItem instance using the Element.closest() method, like so: event.target.closest('smart-accordion-item'). Another approach is to use Event.composedPath() which will return all parents of the current target (including the AccordionItem).

    Best Regards,
    Christopher

    Smart HTML Elements Team
    https://www.htmlelements.com

    #100776
    Avatar
    edwardsmarkf
    Participant

    event.target.closest('smart-accordion-item').dataset.labelnameĀ  Ā šŸ˜

    THANK YOU!

    this is exceptionally useful.Ā  you might consider adding this in the documentation.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.