jquery match elements with style font-size in px

前端 未结 2 961
臣服心动
臣服心动 2021-01-26 13:29

How to target element with inline-style font-size defined in pixels (ex: font-size:12px) in order to modify font-size on a button click.

Can someone help finish this jav

相关标签:
2条回答
  • 2021-01-26 13:41

    You may try indexOf on style attribute:

    $('.parent').each(function (index, value) {
        if (/font-size:[^;]+px/.test($(this).attr('style'))) {
            alert(index + ": " + $(this).attr('style'));
        }
    });
    

    Here is Demo Fiddle

    0 讨论(0)
  • 2021-01-26 13:51

    JQuery .css('font-size') always returns pixels, even if the original size was defined with a different unit. I would use .attr('style') instead (works with inline styles only) :

    var result = $('*').filter(function () {
        var style = $(this).attr('style');
        return /font-size:[^;]+px/.test(style);
    });
    

    Here is a demo : http://jsfiddle.net/wared/8LcD9/.

    0 讨论(0)
提交回复
热议问题