Reputation: 181
I have a problem with my dynamic search. I want to find div with id containing specific text and it works well until I try to find something with accent characters for ex. Ł.
I am using this selector:
$('.user-row[id*='+searchText+']')
I've tried inputs and
val().indexOf(searchText) > 0
but it didn't work either.
Upvotes: 1
Views: 1189
Reputation: 41
Also found a interesting fact with Jquery here, not related to this question though.
Jquery ID selector normally will only select the first element that matches, however for any id names includes accented letters, ID selector will pick up all of them.
Example here :
$('#lesschars').css({backgroundColor: 'blue'});
$('#someŁchars').css({backgroundColor: 'red'});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="user-row" id="lesschars">ID with no accent, will select first element</div>
<div class="user-row" id="lesschars">ID with no accent, will select first element</div>
<br>
<div id="someŁchars" class="user-row">ID with accent, selects both</div>
<div id="someŁchars" class="user-row">ID with accent, selects both</div>
Yeah, I know, there shouldn't be same ID in one page, but good to know this difference
Upvotes: 0
Reputation: 181
Ok, so I made stupid mistake. I was assigning divs ids with php strtolower. Then I was lowering search text, but strtolower didn't work with accent characters so my div was named with Ł not ł. That's why it wasn't found by selector. mb_strtolower did work. Case closed :D
Upvotes: 0
Reputation:
The only problem I can think of is that you aren't using HTML 5.
The HTML 4.01 spec states that ID tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (-), underscores (_), colons (:), and periods (.).
HTML5 gets rid of the additional restrictions on the id attribute.
https://mathiasbynens.be/notes/html5-id-class
So in HTML 5 special accented characters such as the described Ł are definitely allowed within an id.
JSFiddle to demonstrate: http://jsfiddle.net/7cq25865/
$('.user-row[id*='+searchText+']')
does work.
Upvotes: 3