jeudi 15 avril 2021

jQuery next() method not working properly

I'm new to jQuery and I have a problem with next() method.Im currently working on an online exam, Im new to programming so I copy some codes online, so fetch my questions from database then display it like this.

    <div class='myQuestion active'>..</div>
    <div class='myQuestion'>..</div>
    <div class='myQuestion'>..</div>
    <div class='myQuestion'>..</div>
    <div class='myQuestion'>..</div>
    <div class='myQuestion'>..</div>

So each div has form inside with button next and prev so this is the out out enter image description here

But when i click next sometimes it working but most of the time nothing will happened it will just display question 1.

This is the code I copy from some source , but I already change some here.

$(document).on("keydown", e), setTimeout(function() {
          $(".nextbtn").on('click',function() {
              var e = $(".myQuestion.active");
              $(e).removeClass("active"), $(e).next().length == 0  ? (check()) : ($(e).next().addClass("active"), $(".myForm")[0].reset(),
              $(".prebtn").attr("disabled", false));
              setTimeout(function() {
                App.$refs.foo.nxtClick();
              }, 100);
          }),
          $(".prebtn").click(function() {  
              var i;
              var e = $(".myQuestion.active");
              $(e).removeClass("active"),
              $(e).prev().addClass("active"), $(".myForm")[0].reset()
              $(".myQuestion:first-child").hasClass("active") ? $(".prebtn").attr("disabled", true) :   $(".prebtn").attr("disabled", false);
              $(".prebtn").prop("disabled")?i=1:i=0;
              setTimeout(function() {
                App.$refs.foo.prvClick(i);
              }, 100);
          })
      }, 700);

I don't know what's the point of on keydown, but this code is inside already the document.ready function. Can someone help me with this to figure out what is missing or wrong about this code.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire