0
Javascript code to change text on button click, which can return the old text
Hello! I want to create a website where you can change the language. The fact is that on modern sites this happens due to the link when you click on another language. Is it possible to change one text to another by pressing a button in JavaScript?
7 Antworten
+ 6
Can you share your attempt?
+ 1
Yes it is posible.Share some of your code and.
+ 1
you have few errors here,i mean many
1.first you need to load DOM before you find buttons with IDs:
Add in top ;
document.addEventListener("DOMContentLoaded", function() {
*dont forget to close with { on the end
2.you have semicolon on line 4 and you dont need it.
3.Close your functions and if and else stqtements corectly
4.and yea I almost forgot,you use === to check if value is identical not =
**If you still dont menage to do it i can give you more hints
after yoi fix all above you will see that you also have IDs problem
+ 1
yea ok,but since you have only two languahes here you dont need if/else statement at all.You can simplyswitch from one to another language using bolean value atached to your button.
+ 1
it's absolutely possible to create a website where users can change the language by pressing a button using JavaScript. You can achieve this by defining different sets of text for each language and then updating the displayed text based on the user's language choice.
0
I think that changing the language without changing the site can only happen according to this scenario:
We have a button. When clicked, it changes its value. If its value is zero, then there is one language. If the value is equal to one, then changes to another language, and if the value is two, then the value is reset. I have something wrong with the 4th line, while I can't figure out what exactly
https://code.sololearn.com/W6LN5Zr5dQ01/?ref=app
0
Thanks to everyone who answered my question! I optimized the code a bit, when did I find out better about textContent, and the output came out:
https://code.sololearn.com/WGFfwZAno25k/?ref=app