How to get value attribute of element HTML in liquid?

How to get value attribute of element HTML in liquid?

louis2k
Shopify Partner
1 0 0

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.

Reply 1 (1)

PageFly-Amelia
Shopify Partner
576 162 232

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.