Reputation: 97
I need to identify list (li
) items that include a full stop at the very end.
I can work out how to match a full string with
if ($(obj).elements[0].innerHTML === "This list has full stops."
but don't know how to match just a full stop at the end. I tried
if ($(obj).elements[0].innerHTML === "*."
but no good.
Please help
Upvotes: 0
Views: 56
Reputation: 60
Not a big fan of regex, however if you want to do the above thing multiple times and make code easily readable you can create a function for it.
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
And use it like this:
var str = $(obj).elements[0].innerHTML;
if(endsWith(str,'.')){
// Do watever.
}
Upvotes: 0