Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
138
rated 0 times [  140] [ 2]  / answers: 1 / hits: 42778  / 11 Years ago, sat, october 19, 2013, 12:00:00

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?


More From » jquery

 Answers
6

You can always use .filter():



var mans = $('input').filter(function() {
return $(this).attr('name').toLowerCase().indexOf('man') > -1;
});

mans.css('background-color', 'black');


The key part here is toLowerCase() which lowercases the name attribute, allowing you to test it for containing man.


[#74877] Friday, October 18, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaileya

Total Points: 168
Total Questions: 95
Total Answers: 72

Location: Antigua and Barbuda
Member since Sat, Apr 24, 2021
3 Years ago
;