Liquid、JavaScriptなどに関する質問
成功
@SHOKO06 様
初めまして。新垣です。
下記コードを{{ article.content }}が存在するファイル、または、そのファイルが取り込んでいるJSファイルに記述してください。
document.addEventListener('DOMContentLoaded', function() { // ページ読み込み時
const images = document.querySelectorAll('img[alt]'); // alt属性を持つすべての画像を取得
images.forEach(image => {
const altText = image.getAttribute('alt');
if (altText) { // alt属性が存在する場合
const p = document.createElement('p');
p.textContent = altText; // pタグにalt属性のテキストを挿入
p.className = 'article-img_alt'; // classを追加
image.insertAdjacentElement('afterend', p); // 画像の直後にpタグを挿入
}
});
});
以上、ご参考になりましたら幸いです。
成功
@SHOKO06 様
初めまして。新垣です。
下記コードを{{ article.content }}が存在するファイル、または、そのファイルが取り込んでいるJSファイルに記述してください。
document.addEventListener('DOMContentLoaded', function() { // ページ読み込み時
const images = document.querySelectorAll('img[alt]'); // alt属性を持つすべての画像を取得
images.forEach(image => {
const altText = image.getAttribute('alt');
if (altText) { // alt属性が存在する場合
const p = document.createElement('p');
p.textContent = altText; // pタグにalt属性のテキストを挿入
p.className = 'article-img_alt'; // classを追加
image.insertAdjacentElement('afterend', p); // 画像の直後にpタグを挿入
}
});
});
以上、ご参考になりましたら幸いです。
ありがとうございます!
早速試してみます。
無事、こちらで実装できました!ありがとうございました。
いつもShopifyをご利用いただき、ありがとうございます。 Shopifyは、皆様の日本語での利用体験の向上に努めております。さらなる改善のために皆様のご意見をお寄せい...
By JasonH May 9, 2025Shopify アカデミーの学習パスと認定スキルバッジExpanding Your Shopify Business Internationallyを活用して、国際的にビジネ...
By Shopify Feb 7, 2025Shopify アカデミーの学習パスB2B on Shopify:立ち上げとカスタマイズで卸売販売に進出しましょう。これら3つの無料コースは、ShopifyストアでB2B機能...
By Shopify Jan 31, 2025