3

I'm new here. I had a problem with my Modal in my PHP code. It creates morethan one modal whenever I click it. At first click it only shows 1 modal. But when you click it on the second time or more it increments and creates more modals when clicked. Even though the previous modal is closed, it still shows the previous modals when clicked. Here is a sample image when clicked once [Single Modal][1]. And this picture is a sample when it toggles more than 2 modals. [Incrementing Modal][2]

1
  • I’m voting to close this question because in its current status it does not have any meaning. Commented Jun 13, 2020 at 7:15

1 Answer 1

1

The problem is probably inside the append function where you are appending unconditionally without checking if similar div already exists. Change it to

 while (div.children.length > 0) { $t = $(el).find(".bs-example-modal-lg"); if($t.length){ $t.replaceWith(div.children[0]); }else{ $(el).appendChild(div.children[0]); } } 

Checkout this question's answers for more information.

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

3 Comments

$el is not defined
if changed to el. the error is el.find is not a function(…)
Hi @NylzonRedulaII please edit the answer to the version that worked for you, I was not able to run this in an actual browser so it may still have some typos. Also an upvote would be nice :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.