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 javascript code :
html
<div class='parent' style='font-size:15px'>
<div>div 1 no inline styling</div>
<div style='font-size:1em'>div 2 inlined font-size 1em</div>
<div class='div-3'>div 3, CSS font-size:14px;</div>
<div style='font-size:22px'>div 4 inlined font-size 22px</div>
<div style='font-size:16pt'>div 5 inlined font-size 16pt</div>
<div style='font-size:80%'>div 6 inlined font-size 80%</div>
</div>
<div id="output_box"></div>
javascript
$('*').filter(function() {
/*var a-match-in-px-units = some-regular-expression-someelse-can-help-about;*/
return $(this).css('font-size') == '11';
$('#output_box').html($(this));
});
$("#trigger").click(function() {
alert('to initialize font-size in px to bigger/lesser unit function()');
/* This is to apply font-resizing */
});
I prepared a jsFiddle
I found this other answer useful Find elements which have greater font-size than specified
You may try
indexOf
on style attribute:Here is Demo Fiddle
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) :Here is a demo : http://jsfiddle.net/wared/8LcD9/.