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. The jQuery method I've seen is $('element').css('property')
, but this is not working for external css [i.e bootstrap.css].
Should I have to include any more lines of code.
Asked
Active
Viewed 99 times
0

Tushar Gupta - curioustushar
- 58,085
- 24
- 103
- 107

Lonely
- 613
- 3
- 6
- 14
-
why do you want to do it? – Arun P Johny Aug 21 '13 at 02:34
-
I am inputting a string via form and want to have all type of headings of that string from h1 to h6 in a textbox. – Lonely Aug 21 '13 at 02:36
-
for that why do you want to know the css property value – Arun P Johny Aug 21 '13 at 02:39
-
then I can give the value to font-size $textarea.css('font-size', value); – Lonely Aug 21 '13 at 02:41
-
oh, I just recognized that , if I do that the font-size will be fixed for that textbox, is there any way to do that. – Lonely Aug 21 '13 at 02:43
-
Perhaps this will help: [Can jQuery get all CSS styles associated with an element?](http://stackoverflow.com/questions/754607/can-jquery-get-all-css-styles-associated-with-an-element) (there are a few of these solutions here) – dc5 Aug 21 '13 at 04:34
-
The answer I gave you for your [previous question](http://stackoverflow.com/q/18337531/1169519) of this is perfectly valid, it definitely works also with external stylesheets. You've missed something else, for example: are the font-sizes of the `H*` tags defined by classes or by tag selectors? – Teemu Aug 21 '13 at 10:33
2 Answers
0
$.each(['h1','h2','h3','h4','h5','h6'], function(idx, val){
console.log($(val).css('font-size') )
});

Leonardo Gonzalez
- 1,179
- 9
- 9
0
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);

Exception
- 8,111
- 22
- 85
- 136