0

How (can one?) can I open a modal using jQuery or JavaScript, using the HTML element's name attribute value, instead of using the modal id? (I have the same modal id so I don't have to duplicating my css)

I was thinking something like this would do the trick:

<div id="product-description-modal" name="uop-modal" role="dialog" class="modal"></div>
<div id="product-description-modal" name="payu-modal" role="dialog" class="modal"></div>

My jQuery method to open the specific modal:

onShowModal() {
    if (this.showPayAsYouUseModal === true) {
      $('div[name]="payu-modal"').modal('show');
    } else {
      $('div[name]="uop-modal"').modal('show');
    }
}

But I have had no luck so far. What am I missing?

Thank you in advance!

2
  • 4
    This is not about modals, it's about using the proper selector: $('div[name=uop-modal]') should do the trick. (Also, don't use the same id more than once; as "id" suggests it's supposed to be unique. Use a class instead.) Commented Oct 30, 2019 at 17:40
  • Thank you very much! @ChrisG ;). It works like a charm! Commented Oct 30, 2019 at 17:53

1 Answer 1

1

You can select required element with $('div[name=uop-modal]') jQuery selector.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.