jquery 'attribute contains' selector with a dynamic value

前端 未结 2 1691
孤街浪徒
孤街浪徒 2021-01-18 03:41

Let\'s say that i have a variable questionId which is an integer, and i want to find tr elements that have the fragment (\"question_\"+questi

相关标签:
2条回答
  • 2021-01-18 04:09

    You have error:

    var questionId = 7674;
    $("tr[id*='quiz_question_" + questionId + "']");
    

    Notes:

    1. Please use var to declare variables.
    2. questionId is a variable. It is not part of the selector. You should concatenate questionId to the string.
    0 讨论(0)
  • 2021-01-18 04:20

    Yep, you almost had it:

    var selector = "tr[id*='quiz_question_" + questionId + "']";
    $(selector)
    
    0 讨论(0)
提交回复
热议问题