Liquid、JavaScriptなどに関する質問
aタグの中で
にだけスタイルを適用させたいときはどのようにすればよろしいでしょうか。
andではなくorでスタイルあてたいです。
よろしくお願いいたします。
(jQueryでなくとも解決できる、という場合も教えていただければと存じます)
解決済! ベストソリューションを見る。
成功
jQueryではなく直接JavaScriptのコードです。
例として1行目にスタイルを入れております。
ご参考になりますと幸いです。
let cssString = "font-size:10px;color:#000" //スタイル
let styleElementCandidates = document.getElementsByTagName('a')
for (let styleElement of styleElementCandidates){
if (styleElement.children.length == 0){ //子要素がないもの
styleElement.setAttribute('style', cssString)
continue;
}
if (styleElement.classList.length == 0){ //クラス名のないもの
styleElement.setAttribute('style', cssString)
continue;
}
}
成功
jQueryではなく直接JavaScriptのコードです。
例として1行目にスタイルを入れております。
ご参考になりますと幸いです。
let cssString = "font-size:10px;color:#000" //スタイル
let styleElementCandidates = document.getElementsByTagName('a')
for (let styleElement of styleElementCandidates){
if (styleElement.children.length == 0){ //子要素がないもの
styleElement.setAttribute('style', cssString)
continue;
}
if (styleElement.classList.length == 0){ //クラス名のないもの
styleElement.setAttribute('style', cssString)
continue;
}
}
さっそくのお返事ありがとうございます!
試してみますね、助かります!
ありがとうございました!
いつも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