I have used this answer in order to solve a similar problem.
I want to prevent the use of "
and '
When using $("p:contains('" + valor + "')").addClass("on");
, it works.
But when using $('p:contains('" + valor + "')**'**).addClass("on")
, it does not!