Tuesday 15 June 2010

javascript - If Element ID exists then Hide Other Element -



javascript - If Element ID exists then Hide Other Element -

i have ecommerce website has multiple prices given item. trying set bit of script hide price, if lower cost class nowadays on page.

<table> <tbody> <tr> <td> <font> <div class="product_listprice">199.99</div> </font> <font> <div class="product_productprice">179.99</div> </font> <b> <div class="product_saleprice">159.99</div> </b> <font> <div class="product_discountprice">139.99</div> </font> </td> </tr> </tbody> </table>

essentially need script hide .product_productprice if .product_saleprice exists on page, , hide both .product_saleprice , .product_productprice if .product_discountprice exists.

here's i've come far google digging.

<script type="text/javascript"> $(document).ready(function(){ if ( $(".product_discountprice").size() ) $(".product_saleprice, .product_productprice").hide(); }); }); </script>

however, doesn't seem working. ideas? i'm jquery novice, i'm sure there improve way out there...

// need script hide .product_productprice // if .product_saleprice exists on page... if ($('.product_saleprice').length) { $('.product_productprice').hide(); } // ...and hide both .product_saleprice , .product_productprice // if .product_discountprice exists. if ($('.product_discountprice').length ) { $('.product_saleprice, .product_productprice').hide(); }

update adds new class name, instead of hiding:

if ($('.product_saleprice').length) { $('.product_productprice').addclass('some-class'); } if ($('.product_discountprice').length ) { $('.product_saleprice, .product_productprice').addclass('some-class'); }

javascript jquery

No comments:

Post a Comment