Link to home
Start Free TrialLog in
Avatar of Melody Scott
Melody ScottFlag for United States of America

asked on

Jquery If statement need help

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.
Avatar of lenamtl
lenamtl
Flag of Canada image

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.
Avatar of Melody Scott

ASKER

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/
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
But will that work on a page where all the elements are pulled from a template, or will it hide them all?
Brilliant!! Thanks so much!
you welcome