JS/jQueryでCSS疑似要素である:before:afterのプロパティを取得し変更する jQueryにはCSSのプロパティを取得できる css() という関数がありますが、残念ながら疑似要素には対応していません。 サンプル要素 .pseudo::before { content: '疑似要素取得'; } 今回はこの要素の content の値を取得・変更していきます。 取得する var property = window.getComputedStyle($('.pseudo')[0], '::before').getPropertyValue('content'); console.log(property); // 疑似要素取得 JSの関数を使って疑似要素のプロパティを取得することができます。 getComputedStyle() 関数の第二引数に ::before または :
![JS/jQueryでCSS疑似要素である:before:afterのプロパティを取得し変更する | ITハット](https://cdn-ak-scissors.b.st-hatena.com/image/square/d0e65cb17feb02e4562b94d0872b68249f84cccf/height=288;version=1;width=512/http%3A%2F%2Fithat.me%2Fwp-content%2Fuploads%2F2016%2F09%2Fjs-jquery-pseudo-element-property-get-and-set.png)