javascript - Removing Size and font-size from child elements -
i want remove element attributes divs. divs generated automatically. want iterate through each div , child divs , want remove font-size (font-size: xpx)
, size
inside font tag <font size="x">
.
these examples of div.
<div id="headline" class="headline" style="position: word-break: break-all; background-color: rgb(90, 88, 84); width:300px;height:250px"> <div style="text-align: center; font-size: 12px; color: rgb(1, 69, 18);"> <div> <div> <font color="#ffffff" size="6" > <b>this is </b> </font> <b style="color: rgb(255, 255, 255); font-size: xx-large;">a test </b> </div> </div> <div> <div> <b style="color: rgb(255, 255, 255); font-size: xx-large;">demo </b> </div> </div> <div> <b style="color: rgb(255, 255, 255); font-size: xx-large;">csa</b> </div> </div> </div>
or
<div id="headline" class="headline" style="position: absolute; width: 186px; height: 50px; "> <div style="text-align: center; font-size: 12px; color: rgb(249, 249, 251);"> <span style="color: rgb(255, 204, 153);"> <font size="4">expansion pack</font> </span> </div> </div>
i reading divs like.
$('#headline').find('*').each(function() { // font-size remove //size inside tag remove });
but how can remove font-size , size if in child element, font-size present , there no <font>
tag
i think need more explicit selectors. should work:
// select elements style attribute contains font-size, , // remove inline font-size property $('[style*="font-size"]').css('font-size', ''); // select font elements size attribute, , // remove size attribute $('font[size]').removeattr('size');
you may want make selectors more specific avoid modifying content unexpectedly. example:
$('#headline [style*="font-size"]').css('font-size', '');
note: solution uses jquery attribute selectors.
edit: see comments charlie performance. attribute selectors slower other selectors, i'd bet in use cases speed differences won't matter.
Comments
Post a Comment