2
スタイルシート/スタイルタグから適用されているdivのスタイルを取得して、要素スタイルをプログラムで無視するにはどうすればよいですか?クラスから継承した要素スタイルを取得する*スタイル属性ではない
var alice = 'alice ' + $('.alice').css('color');
var boblice = 'alice ' + $('.bob').css('color');
var bob = 'bob ' + $('.bob').css('color');
$('#result').text(
alice + '\n' + bob
);
$('#expected').text(
boblice + '\n' + bob
);
var elem1 = document.getElementById("alice");
alicestyle = window.getComputedStyle(elem1, null);
console.log(alicestyle);
.alice {
color:green;
}
.bob {
color:green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='alice' class="alice" style="color:red">
test
</div>
<div id = 'bob' class="bob">
test
</div>
result:
<div id="result">
</div>
expected:
<div id="expected">
</div>
getComputedStyle:
<div id="computed">
</div>
[** 'getComputedStyle' **](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle)のようなものですか? –
このリンクは役立つことがありますhttps://stackoverflow.com/questions/16778814/read-css-property-from-stylesheet – Aravinder
@ibrahimmahrirいいえ、getComputedStyleにはスタイル属性が含まれています。 –