html - jQuery dealing id="q1" and id="q10" as same -
i calling (from jquery) divs id="q0"
, id="q1
"... id="q10"
1 one. when it(jquery) calls div="q1" calls div="q10" simultaneously.
using characters @ end didn't work.
//jquery $( document ).ready(function() { $(".container").hide(); var number=0; var question="question"; var question_number=question.concat(number); $('[id*='+question_number+']').show(); $(".submit").click(function (e) { $(".container").hide(); number++; var question_number=question.concat(number); alert(question_number); $('[id*='+question_number+']').show(); }); }); ////////////////html <div id="question1" class="container"> <button class="submit">submit</button> </div> /////so on <div id="question10" class="container"> <button class="submit">submit</button> </div>
the *=
attribute substring selector match element attribute contains give it. [id*=1]
match any element id
attribute contains 1
, of course question1
, question10
(and foo717
).
to hide single specific question, use id selector: $("#question" + question_number)
Comments
Post a Comment