I have a div element with a couple of inputs. When I started coding this, I had jQuery only, and my click event for the inputs was working properly.
Then, I added Bootstrap, and the event just stopped working.
This is the code
<!DOCTYPE html>
<html>
<head>
<title>Qué Pido?</title>
</head>
<body>
<p id="que-pido"></p>
<!-- jQuery and Bootstrap -->
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function() {
getFromEndpoint("clasicas");
});
function getFromEndpoint(endpoint) {
$(document).ready(function() {
$.get( "que" + "/" + endpoint, function( data ) {
console.log(data);
$( "#que-pido" ).html( data );
});
});
}
$(document).ready(function() {
$(".categorias").click(function() {
console.log("clicked: " + $(this));
var endpoint = $(this).attr('id');
getFromEndpoint(endpoint);
});
});
</script>
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-outline-primary active">
<input type="radio" name="categorias" class="categorias" id="clasicas" autocomplete="off" checked> Clásicas
</label>
<label class="btn btn-outline-primary">
<input type="radio" name="categorias" class="categorias" id="etnicas" autocomplete="off"> Étnicas
</label>
<label class="btn btn-outline-primary">
<input type="radio" name="categorias" class="categorias" id="todas" autocomplete="off"> Todas
</label>
</div>
</body>
</html>
If I remove the labels, then the click method is properly fired... but of course, I get none of the CSS that Bootstrap provides.
I also tried removing Bootstrap's JS, but then I lose the animation that happens when pressing each button, and I'd like to keep that if possible.
Any ideas on this?
Thanks in advance
console.log(data);isn't even logged