1
Hey there, guys! I am an industrial designer (designer and illustrator) by training and not a programmer, but I love learning and programming, you see, I’m curious! I’m experiencing a plugin from jQuery to client side translations on a website - the "Translate.js", and I thought it would be interesting if the translations were triggered by a "button", flags of the chosen country / language. My "button" works to a certain extent. When I try to click on the class that was added by jQuery the thing goes off. If you can help me, I would be very grateful. Follow the codes for analysis:
(Obs.: the function of debug "console.log()" is playing the role of the plugin, to simplify the concept.)
THE HTML
<!-- ESP -->
<img class="img-esp" src="esp.png" />
<!-- FRA -->
<img class="img-fra" src="fra.png" />
THE CSS
/*
CSS
*/
.img-esp,
.img-fra,
.img-por { cursor: pointer; }
The images
THE JQUERY
<script src="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 image of the flag of Brazil is loaded, why can not trigger a function from the image, as the translation or the "console.log()" same. How is it possible to do this? Thanks for your help, thank you very much!
The heart of the matter is "dynamically", I understand what you said, thank you very much!
– Alexandre Soares da Silva