Jquery If statement need help

Melody Scott
Melody Scott used Ask the Experts™
on
Hi, Please see here: https://www.magickitchen.com/menu/thanksgiving.html. One of the items says Build your own Package or Add to your Order.

On that one, I'd like to hide the dropdown and the add to cart button.

The dropdown has a title of Nothing Selected. <button type="button" class="btn dropdown-toggle bs-placeholder btn-default" data-toggle="dropdown" role="button" title="Nothing selected"><span class="filter-option pull-left">Nothing selected</span>&nbsp;<span class="bs-caret"><span class="caret"></span></span></button>

Can I use Jquery to say, if this title says nothing selected, display none?

Ideally, I'd like to add a display:none to this div: <div class="order-form">, but just on that item.

The page is generated from a template, so I have to use an if query somehow, I don't want all order forms to disappear.

Thanks, I hope that made some sense.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

what I would do to hide the dropdown
is to use PHP code to show or hide the dropdown based on condition, never use JavaScript for that or CSS as user can bypass this from browser console.

Usually custom item will have different values with selection called attribute.
You can have a button that say create your package then it goes to product form with all selection then the add to cart button will be on that page.

It's not making sens to send that item directly to the cart without any kind of selection.

Again never rely on JavaScript specially for shopping cart...

Most of the shopping have attribute plugin or extensions, you seems to use custom cart.
Using Opencart for example have attribution in the default package and you can set price to each items, so this is great for build your own custom product.

Author

Commented:
I can't use php on this site, developer won't allow it. It is a custom cart. If I was to use jquery, would something like this work?

var $item = $('.filter-option');

if ($item.text() == Nothing selected)​​ {
    $item.parent().siblings('.order-form').hide();
}​
Hi,

If you cannot use PHP or change template code then

you could add display none class the the div or item
https://getbootstrap.com/docs/4.3/utilities/display/#hiding-elements

or

You could add disabled attribute to the form element.
$('.someElement').attr('disabled', 'disabled');

Open in new window


you can check the documentation
https://api.jquery.com/attr/
https://api.jquery.com/prop/
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Multitechnician
Top Expert 2014
Commented:
<script>
jQuery(function($) { // <=== wait document ready
    $(".order-form", $("h4:contains('Build your own Package or Add to your Order')").closest(".result")).css("visibility","hidden");
});
</script>

Open in new window


Capture.JPG

Author

Commented:
But will that work on a page where all the elements are pulled from a template, or will it hide them all?

Author

Commented:
Brilliant!! Thanks so much!
leakim971Multitechnician
Top Expert 2014

Commented:
you welcome

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial