1
When I click a button .click
, my JS runs a function and updates the fields with the class .click
. But why when HTML is updated and clicked on .click
again nothing happens as if the class does not exist?
Javascript:
$(function () {
$(".click").click(function () {
$.get("http://localhost/test/api.php", function (data) {
alert(data);
$(".content").html(data);
})
})
})
HTML:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<div class="content">
<div class="click">ops</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script src="functions.js"></script>
</body>
</html>
When I first click on .click
, search for the HTML of api.php
(<div class="click">eita</div>
), which is placed in .content
.
But if I click again on .click
after reloading, content with AJAX’s HTML simply does nothing else. Why?
What is the HTML of the page
http://localhost/test/api.php
? Edit the question to include it.– Luiz Felipe
code
<div class="click">Eita</div>– Gilberto Gonçalves