Is there a cross-browser method of getting the used css values of all properties of all elements?

前端 未结 2 809
孤城傲影
孤城傲影 2021-01-12 17:57

I\'m looking to get the used css values of all DOM elements on a page. When I say "used values" I\'m referring to the definition as specified in the W3C specificat

2条回答
  •  臣服心动
    2021-01-12 18:31

    You could use jQuery or another preferred library in most cases.

    For instance, your question title has font-size:100% applied to it which can be retrieved w/firebug. But with jQuery api you can retrieve the value used like so:

    $('#question-header .question-hyperlink').css('font-size');//run in console
    //or enter this in the url bar
    //javascript:alert($('#question-header .question-hyperlink').css('font-size'));
    //returns "23.06px"
    

    NB the library is included on this page, but it would be fairly trivial to create a bookmarklet that includes jQuery and polls the necessary properties.

提交回复
热议问题