Hello everyone! I am an industrial designer (designer and illustrator) for training and not a programmer, but I really like learning and programming, you see, I'm a curious person! I'm trying out a jQuery plugin for client-side translations on a website - the "translate.js", and I thought it would be interesting if the translations were triggered by a "button", flag country / chosen language. My "button" works to some extent. When I try to click on the class that was added by jQuery the thing goes away. If you can help me, I'll be very grateful. Here are the codes for review:
(Note: the debug function "console.log ()" is playing the plugin function to simplify the concept.)
HTML
<!-- ESP -->
<img class="img-esp" src="esp.png" />
<!-- FRA -->
<img class="img-fra" src="fra.png" />
CSS
/*
CSS
*/
.img-esp,
.img-fra,
.img-por { cursor: pointer; }
Images
JQUERY
<scriptsrc="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"> /* From JQUERY CDN */ </script>
<script>
/*
JQUERY
*/
$(document).ready(function() {
$(".img-esp").on("click", function() {
// Mudar a bandeirinha da Espanha para a do Brasil
$(".img-esp").attr("src", "bra.png");
$(".img-fra").attr("src", "fra.png");
$(".img-esp").addClass("img-por");
// Funciona!
console.log("ESP para BRA");
});
$(".img-fra").on("click", function() {
// Mudar a bandeirinha da França para a do Brasil
$(".img-fra").attr("src", "bra.png");
$(".img-esp").attr("src", "esp.png");
$(".img-fra").addClass("img-por");
// Funciona!
console.log("FRA para BRA");
});
$(".img-por").on("click", function() {
$(".img-esp").attr("src", "esp.png");
$(".img-fra").attr("src", "fra.png");
// Não funciona! Por quê?!
console.log("BRASIL");
});
}); </script>
Once the Brazilian flag image is loaded, why can not I fire a function from the image, such as the translation or the "console.log ()" itself. How is this possible? Right now, thank you for the help, thank you!