How to pass a <button> element (with an id) to menu_item in shell component instead of a link? #910
-
❓ How to pass a element (with an id) to menu_item in shell component instead of a link? Hi, 💡 Goal I want to have the menu item render a with a specific ID so that it can be hooked by JavaScript later (e.g., to trigger an install prompt for a PWA).Right now, I generate the button using a separate SQL file that includes raw HTML. Here’s what I’m doing:
📌 Question Is there a way to avoid using an external SQL file for this and still have a menu_item behave like a button (not a link), so I can bind JavaScript to it directly (e.g., document.getElementById("installBtn").addEventListener(...))? Any suggestions or recommended approaches? Thanks in advance! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi ! But in your case, it sounds like you don't need it. You can create a normal menu item with select
'shell' as component,
JSON('{"link":"#xxx","title":"Install","icon":"download"}') as menu_item; and then select it from your javascript with document.querySelector("nav a[href='#xxx']") |
Beta Was this translation helpful? Give feedback.
Hi !
SQLPage does not allow you to insert arbitrary elements as menu items without creating your own shell as a custom component.
But in your case, it sounds like you don't need it. You can create a normal menu item with
and then select it from your javascript with