I have a Shopify liquid I load into HTML Template
<script type="text/template" id="description">
<div class="product-ddd">
{{ product.description }}
</div>
</script>
<script>
$("#description").each(function() {
console.log($(this).html());
});
</script>
For some reason, find is not working
<script>
$("#description").find('h4').each(function() {
console.log($(this).html());
});
</script>
This is what {{ product.description }}
returns
<div class="product-ddd">
<h4>DETAILS & DIMENSIONS</h4>
<p>A trendy fashion-forward look has never been so comfortable. This full-length maxi dress for women is a must-have year-round style. Featuring a lovely scoop neckline, elbow-length sleeves, full A-line skirt, ankle-length hemline, and it is made from
a soft comfortable stretch material. Pair this maxi dress with a denim or leather jacket for a stylishly edgy look. Available in four stylish colors and it is machine washable for easy care. Made in the USA from a comfortable stretch material.
</p>
<h4>FABRIC CONTENT & CARE</h4>
</div>
This is the final Script Template
<script type="text/template" id="hesdsdllo">
<div class="product-ddd">
<h4>DETAILS & DIMENSIONS</h4>
<p>A trendy fashion-forward look has never been so comfortable. This full-length maxi dress for women is a must-have year-round style. Featuring a lovely scoop neckline, elbow-length sleeves, full A-line skirt, ankle-length hemline, and it is made from
a soft comfortable stretch material. Pair this maxi dress with a denim or leather jacket for a stylishly edgy look. Available in four stylish colors and it is machine washable for easy care. Made in the USA from a comfortable stretch material.
<br
data-mce-fragment="1"> </p>
<h4>FABRIC CONTENT & CARE</h4>
</div>
</script>
2
Answers
Are you sure the template parser replaces
{{ product.description }}
only? I suspect it replaces the whole<script></script>
block. Try this way:The issue is because the
<script>
tag is oftype="text/template"
. This means that the HTML within it is not rendered as part of the DOM, but instead treated as plain text.Therefore, to get the content from it, you need to parse the string to create a DOM from it and then use jQuery (or plain JS) methods to retrieve whatever values you need from it. Try this: