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?
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?
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
$.validator.addMethod("R",function(value,element){
var $firstnames= (value.toLowerCase());
var $search= ("SHIVA" || "KARTHIK" ==$firstnames ? false :true ) ;
return $search ;
}, "This user is blocked");
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!