Privla
Privla

Reputation: 1

hide element if specific text (price 0) is displayed in span

I'm trying to figure out how I can hide a vehicle that he has price 0 so that customers won't be able to see and select it. I'm using Divi wordpress theme.

<div class="chbs-vehicle-list">
                <ul class="chbs-list-reset"><li>
        <div class="chbs-vehicle chbs-clear-fix" data-id="46">

            <div class="chbs-vehicle-image" style="opacity: 1;"><img src="https://www.x.comr/wp/wp-content/uploads/05.png" alt=""></div>

            <div class="chbs-vehicle-content">

                <div class="chbs-vehicle-content-header"> 
                    <span>MINIBUS</span>
                    <a href="#" class="chbs-button chbs-button-style-2 ">
                        Select
                        <span class="chbs-meta-icon-tick"></span>
                    </a>
                </div>


            <div class="chbs-vehicle-content-price">
                <span>
                    <span><sup>€</sup>0<sup>.00</sup></span>
                </span>
            </div>  

jQuery

<script>
jQuery(document).ready(function($) {
if($(".chbs-vehicle-content-price span:contains('0')")){
    $('[data-id="46"]').css({"display":"none"});
}
});
</script>

p.s. I'm a beginner in jQuery so I apologize if I was completely wrong.

Upvotes: 0

Views: 57

Answers (1)

Darren Keen.
Darren Keen.

Reputation: 532

Your code has an issue where you are only checking for a "0" which means when the price is €8.00 it will still hide the car because there is a 0 present.

One way to check that it is €0.00 below:

if($(".chbs-vehicle-content-price span:contains('€0.00')").length){
    $('[data-id="46"]').hide();
}

Upvotes: 1

Related Questions