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

456
Views
Why is toLowerCase() reversing text — why?

I am using toLowerCase() to convert a content editable div to lowercase. But it's also reversing the text! Can someone please tell me why this is happening?

$(document).ready(function() {
  $('#user').bind('keyup', function() {
    $(this).text($(this).text().toLowerCase());
  });
});
#user {
  background: #f1f1f1;
  padding: 1em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="user" contenteditable="true"></div>

Fiddle: https://jsfiddle.net/professorsamoff/8zyvc202/3/

Thanks, Tim

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

It has to do with the quirkiness of browsers... When the text is being set, the cursor moves to the beginning of the editable area.

A less quirky solution might be to convert to lowercase using CSS while the user is typing. Then, if you want to go above and beyond, do the actual conversion in JavaScript on the blur event.

$(document).ready(function() {
  $('#user').blur(function() {
    console.log('Converting from '+$(this).text()+' to '+$(this).text().toLowerCase());
    $(this).text($(this).text().toLowerCase());
  });
});
#user {
  background: #f1f1f1;
  padding: 1em;
  text-transform:lowercase;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="user" contenteditable="true"></div>

about 4 years ago · Santiago Trujillo Report

0

Can be achieved using css

#user {
  background: #f1f1f1;
  padding: 1em;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="user" contenteditable="true" style="text-transform: lowercase"></div>

about 4 years ago · Santiago Trujillo Report

0

Please try the following:

$(document).ready(function() {
    $('#user').bind('keyup', function() {
        $(this).val($(this).val().toLowerCase());
    });
});
about 4 years ago · Santiago Trujillo 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!