Quantcast
Channel: CSSタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8833

CSSの擬似要素(content)を多言語化する

$
0
0

はじめに

Railsアプリのi18n(tメソッド)をJSでも使用できるようにしています。
CSSの擬似要素(content)を多言語化したかったのですが、style内でjavascriptは使えないのでどのように実装するか悩みました。

解決策

JQueryのappendで擬似要素を追加しました。

test.html
<divclass="myclass">質問</div>
test.js
constrequired=I18n.t('helpers.required')$('head').append(`<style>.myclass:before { content: "${required}" }</style>`);

Viewing all articles
Browse latest Browse all 8833

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>