Lowercase and Uppercase with jQuery

Jquery

Jquery Problem Overview


How do I transpose a string to lowercase using jQuery? I've tried

var jIsHasKids = $('#chkIsHasKids').attr('checked').toLowerCase();

but it doesn't work. What am I doing wrong?

Jquery Solutions


Solution 1 - Jquery

I think you want to lowercase the checked value? Try:

var jIsHasKids = $('#chkIsHasKids:checked').val().toLowerCase();

or you want to check it, then get its value as lowercase:

var jIsHasKids = $('#chkIsHasKids').attr("checked", true).val().toLowerCase();

Solution 2 - Jquery

If it's just for display purposes, you can render the text as upper or lower case in pure CSS, without any Javascript using the text-transform property:

.myclass {
    text-transform: lowercase;
}

See https://developer.mozilla.org/en/CSS/text-transform for more info.

However, note that this doesn't actually change the value to lower case; it just displays it that way. This means that if you examine the contents of the element (ie using Javascript), it will still be in its original format.

Solution 3 - Jquery

Try this:

var jIsHasKids = $('#chkIsHasKids').attr('checked');
jIsHasKids = jIsHasKids.toString().toLowerCase();
//OR
jIsHasKids = jIsHasKids.val().toLowerCase();

Possible duplicate with: How do I use jQuery to ignore case when selecting

Solution 4 - Jquery

This question was asked in 2011. I am answering it in September, 2021. Even though I am late by 10 years I am answering for future searchers. Good answers are already given. I will just add an alternate with jQuery's .css property.

$('#chkIsHasKids').attr("checked").val().css("text-transform","lowercase");

This will first check if the id #chkIsHasKids is checked, then will take it's value and then transform it to lower case using the CSS property. That's it!

Solution 5 - Jquery

$.validator.addMethod("R",function(value,element){

var $firstnames= (value.toLowerCase());
 var $search= ("SHIVA" || "KARTHIK" ==$firstnames  ? false :true ) ;
 return $search ;

}, "This user is blocked");

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKris-IView Question on Stackoverflow
Solution 1 - Jquerykarim79View Answer on Stackoverflow
Solution 2 - JquerySpudleyView Answer on Stackoverflow
Solution 3 - Jqueryr.piesnikowskiView Answer on Stackoverflow
Solution 4 - JqueryRelaxing MusicView Answer on Stackoverflow
Solution 5 - JqueryShiv kumar KView Answer on Stackoverflow