How can i get default font size in pixels by using JavaScript or JQuery?

前端 未结 9 1459
Happy的楠姐
Happy的楠姐 2021-02-04 09:07

As you know em is a relative font measurement where one em is equal to the height of the letter \"M\" in the default font size. An advantage in using it is because you will be a

9条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 09:44

    Using jQuery (assuming that you want the font size of a specific element):

    var originalFontSize = $('#your_element_id_here').css('font-size');

    If you're using Prototype as well as jQuery, you'll want to use the jQuery prefix instead of the dollar sign:

    var originalFontSize = jQuery('#your_element_id_here').css('font-size');
    

    This will return the value as a string like so: 16px.

提交回复
热议问题