All things Shopify and commerce
I want to get a value of the data attribute of an html tag using liquid. For example:
<div data-text="a">a</div>
I want to assign a variable liquid to data-text.
Please help me get a solution for this problem. Thanks very much.
Hello @louis2k
This is Amelia at PageFly - Shopify Advanced Page Builder app.
You can try the following steps I have provided to help you solve the problem you are facing:
Step 1: Create a attribute for this tag like id="element"
Step 2: Add code below:
<script>
const el = document.getElementById("element");
el.innerText = el.getAttribute("data-text");
</script>
Hoping my solution helps you solve your problem.
Best regards,
Amelia | PageFly
Please let me know if it works by giving it a Like or marking it as a solution!
➜ Optimize your Shopify store with PageFly Page Builder (Free plan available)
➜ Weekly updated Shopify tutorials on YouTube
All features are available from Free plan. Live Chat Support is available 24/7.
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024