Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
my jquery toggle function is not toggling

I'm trying to get the button to toggle between showing text in different languages. When I click the button nothing happens, can someone help out please?

$(document).ready(function() {
  $('[lang="jp"]').hide();
  $(document).on('click', '#switch-language', function() {
    $('[lang="en"]').toggle();
    $('[lang="jp"]').toggle();
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="switch-lang">Switch Language</button>
<p lang="en">eigo</p>
<p lang="jp">en japon</p>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have a typo in your Selector.

$(document).ready(function() {
  $('[lang="jp"]').hide();
  $(document).on('click', '#switch-lang', function() {
    $('p[lang="en"]').toggle();
    $('p[lang="jp"]').toggle();
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="switch-lang">Switch Language</button>
<p lang="en">eigo</p>
<p lang="jp">en japon</p>

No element has "switch-language" as the ID. When you change it to the correct value, "switch-lang", it works.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!