front-end_junior
front-end_junior

Reputation: 130

jquery change element on php if statement

I try to change html element, on php if statement, I tried this:

<?if ($item['DISCOUNT_PRICE']<$item['PRICE'] AND $item['DISCOUNT_PRICE']>0):?>
                                    <?//MM-227?>
                                    <div class="catalog-product__old-price-outer">
                                        <?=price($item['PRICE'], $item['CURRENCY'])?>
                                    </div>
                                    <?//MM-227?>
                                    <script>
                                        $(".inner-price-block .price-offer").css("color","red");
                                    </script>
                                <?endif;?>
<div class="inner-price-block">
<div id="sku_price_<?=$item['ID']?>" class="price-offer">
                                            <?=price($item['DISCOUNT_PRICE'], $item['CURRENCY']);?>
                                        </div>
</div>

I try to change class price-offer, with this script:

 <script>
                                        $(".inner-price-block .price-offer").css("color","red");
                                    </script>

what I missed?

Upvotes: 0

Views: 57

Answers (2)

Happy Coding
Happy Coding

Reputation: 2525

Try this :

<script>
                    $(document).ready(function() {
                                        $(".inner-price-block .price-offer").css("color","red");
                    });
                                    </script>

Upvotes: 1

Disha V.
Disha V.

Reputation: 1864

You can use php instead of jquery to put condition like below:

<?php $color="";
if ($item['DISCOUNT_PRICE']<$item['PRICE'] AND $item['DISCOUNT_PRICE']>0):
    $color="red";?>
    <?//MM-227?>
    <div class="catalog-product__old-price-outer">
        <?=price($item['PRICE'], $item['CURRENCY'])?>
    </div>
<?php endif;?>

<div class="inner-price-block">
    <div id="sku_price_<?=$item['ID']?>" class="price-offer" <?= ($color!=''?'style="color:'.$color.'":""'?>>
        <?=price($item['DISCOUNT_PRICE'], $item['CURRENCY']);?>
    </div>
</div>

Upvotes: 0

Related Questions