[英]Get a css value from Bootstrap css with JavaScript/ jQuery?
I want to get the font sizes of headings h1,h2,h3,h4,h5,h6
which are respectively 36px, 30px, 24px, 18px, 14px, 12px
respectively [in bootstrap.css] and alert them in the console. 我想获取标题
h1,h2,h3,h4,h5,h6
的字体大小,它们分别在bootstrap.css中分别为36px, 30px, 24px, 18px, 14px, 12px
,并在控制台中提醒它们。 The jQuery method I've seen is $('element').css('property')
, but this is not working for external css [ie bootstrap.css]. 我见过的jQuery方法是
$('element').css('property')
,但这不适用于外部CSS [即bootstrap.css]。 Should I have to include any more lines of code. 我是否应该包含更多代码行。
$.each(['h1','h2','h3','h4','h5','h6'], function(idx, val){
console.log($(val).css('font-size') )
});
var stylesheet = document.styleSheets[(document.styleSheets.length - 1)];
for( var i in document.styleSheets ){
var temp = = document.styleSheets[i];
if( temp.href && temp.href.indexOf("bootstrap.css") ) {
stylesheet = temp;
break;
}
}
var ruleList = stylesheet.cssRules, allRules = [];
for (var rule = 0; rule < ruleList.length; rule ++){
allRules.push( [rule, ruleList[rule].selectorText] );
}
console.log(addRules);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.