简体   繁体   中英

Wrap HTML around existing elements

This is my normal css to apply :

<h3><strong><span style="color: #3399ff;"></span></strong></h3>

I wish to apply that style above to these js elements:

$('#no_tax_price').text("$"+no_tax_price.toFixed(2));
        $('#tax').text("$"+tax.toFixed(2));
        $('#tax_price').text("$"+(no_tax_price+tax).toFixed(2));

If you define your styles in CSS rather than HTML, your new elements will automatically take on the styling - no JS required.

#no_tax_price, #tax, #tax_price {
    font-size: 18pt;
    font-weight: bold;
    color: #3399ff;
}

Normally I wouldn't use <h3><strong><span> to apply styles (instead just use a single class with the right CSS properties defined), but a quick fix is to just wrap those elements around the contents of your "jQuery elements":

$('#no_tax_price, #tax, #tax_price')
    .wrapInner('<h3><strong><span style="color: #3399ff;"></span></strong></h3>');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM