I have html site and I want to find element using text with parentheses. For example I have divs with spans like this:
#container
.div
%span= "example (1)"
.div
%span= "example (22)"
I want to get span with text "example (22)". I have method I use to get those elements. I tried following solutions:
getElement: (title, count) =>
#title = 'example', count = 22
# First try
$("#container span:contains(#{title} (#{count})")
# Second try
filter = new RegExp(title+"//("+count+"//)")
$("#container span").filter (i, el) ->
return !!$(el).text().match(filter)
But I found nothing. How to improve my method? Thanks for all answers.
I have no idea why you try to do with RegExp. If you need some pattern, it could be. but that's heavy. if you want to match a text with static string, just compare via
==
in JavaScript,is
in CoffeeScript. Above source is written with vanilla not jQuery, but I think it's enough for what I wanna say.