Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Daniel1836's avatar

jQuery not working within my modal

I need to use jQuery to call a function on show of my Bootstrap Modal.

$('#Modal').on('show.bs.modal', function (event) {...

This usually works. But I need to use it with a modal within a modal, which does not work. It can't detect the ID of the modal pop-up then. Maybe because of the DOM or maybe the page isn't ready...

I tested this with console.log and this is where it's breaking down.

How do I ensure that my jQuery works even if it is contained inside a modal?

Thanks

0 likes
6 replies
jlrdw's avatar

Why do you need a modal in a modal?

Daniel1836's avatar

Maybe not ideal, but that's what was requested of me.

jlrdw's avatar

Try your second modal with plain js and some css.

Daniel1836's avatar

How would I rewrite this code in plain javascript?

$('#confirm-delete').on('show.bs.modal', function (event) {
    var id = $(event.relatedTarget).data('id');
    $(this).find("#entryId").val(id);
});

I need to:

  1. Determine when the modal by that ID opens.
  2. Store the attribute named (id) in a variable.
  3. Give the ID #entryId the value of that variable.
Daniel1836's avatar

I need to start at the first step. It won't even find the ID in the jQuery selector.

Please or to participate in this conversation.