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 Answer
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.
3 Comments
Feyris
$el is not defined
Feyris
if changed to el. the error is el.find is not a function(…)
Japheth Ongeri - inkalimeva
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