Javascript string case-insensitive comparisons can be performed with string.toUpperCase.
var x = document.getElementById('MY_DIV').name;
x = x.toUpperCase(); //use this line
if (x == "STRING TO MATCH"){
}
Referenced to tutorialsPoint Example for using ignoreCase property
<html>
<head>
<title>JavaScript RegExp ignoreCase Property</title>
</head>
<body>
<script type="text/javascript">
var re = new RegExp( "string" );
if ( re.ignoreCase ){
document.write("Test1-ignoreCase property is set");
}else{
document.write("Test1-ignoreCase property is not set");
}
re = new RegExp( "string", "i" );
if ( re.ignoreCase ){
document.write("<br/>Test2-ignoreCase property is set");
}else{
document.write("<br/>Test2-ignoreCase property is not set");
}
</script>
</body>
</html>
Output
Test1 - ignoreCase property is not set
Test2 - ignoreCase property is set
Code updated for D.K function
function myfunc()
{
var x = document.getElementById('MY_DIV').name;
//x = x.toUpperCase(); // check the result with / without un-commenting this line
var re = new RegExp( x );
if ( re.ignoreCase ){
document.write("X - Test1-ignoreCase property is set");
}else{
document.write("X - Test1-ignoreCase property is not set");
}
re = new RegExp( x, "i" );
if ( re.ignoreCase ){
document.write("<br/> X - Test2-ignoreCase property is set");
}else{
document.write("<br/>X - Test2-ignoreCase property is not set");
}
x = x.toUpperCase(); // ignoring case
document.getElementById(x).value=2;
}