Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lowercase and Uppercase with jQuery

Tags:

jquery

People also ask

How do I convert a string to lowercase in jQuery?

The toLowerCase() method converts a string to lowercase letters. The toLowerCase() method does not change the original string.

What is uppercase and lowercase in JavaScript?

JavaScript provides two helpful functions for converting text to uppercase and lowercase. String. toLowerCase() converts a string to lowercase, and String. toUpperCase() converts a string to uppercase. var text = 'This sentence has some MIXED CASE LeTTeRs in it.

How do I use toUpperCase in JavaScript?

The toUpperCase() method returns the calling string value converted to uppercase. To convert a string to uppercase in JavaScript, use the toUpperCase() method. The toUpperCase() method does not affect the value of the string since JavaScript strings are immutable.


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();

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.


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