jQuery contains() with a variable syntax

后端 未结 3 846
面向向阳花
面向向阳花 2020-12-03 13:50

I have an \"uncaught exception: Syntax error, unrecognized expression: )\" in a jQuery application.

The code is:



        
相关标签:
3条回答
  • 2020-12-03 13:56

    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!

    0 讨论(0)
  • 2020-12-03 14:03

    Old question, but I must leave a note for future generations. Andrew's answer (the accepted one) didn't work for me. What did work was using a pre-made string as selector. Borrowing OP's examples:

    var selector = "p:contains("+ vtxt +")";
    $(selector).addClass("on");
    
    0 讨论(0)
  • 2020-12-03 14:06

    Try this:

    $("p:contains('" + vtxt + "')").addClass("on");
    
    0 讨论(0)
提交回复
热议问题