I am doing the following using attribute contains selector $('[attribute*=value]')
<input name="man-news">
<input name="milkMan">
<script>
$( "input[name*='man']").css("background-color:black");
</script>
This works for the 1st input but not the second input as "Man" has a capital "M"
How can I make $( "input[name*='man']")
an case insensitive selector?
I was just able to ignore jQuery's case sensetivity altogether to achieve what I want using below code,
You can use this link to find code based on your jQuery versions, https://css-tricks.com/snippets/jquery/make-jquery-contains-case-insensitive/
Also there is this article where it does to many good things with jquery: http://www.ultechspot.com/jquery/using-jquery-search-html-text-and-show-or-hide-accordingly
This works for me using jQuery and if i'm adding item to a table
The simplest way to do this is to add a case insensitivity flag 'i' inside the regex part of the selector:
So instead of
$( "input[name*='man']")
You could do
$( "input[name*='man' i]")
JS fiddle: https://jsfiddle.net/uoxvwxd1/3/
You can always use
.filter()
:The key part here is
toLowerCase()
which lowercases thename
attribute, allowing you to test it for containingman
.*REGEX_VALUE* - the value you want to find
I ended up using regex to validate whether the attribute 'ID' satisfy... regex is much more flexible if you want to find a certain matching value or values, case sensitive or insensitive or a certain range of values...