Home  >  Q&A  >  body text

About jq traversing each() - Stack Overflow

       var aBtn = $('#block_nav').find('a');
       //     console.log(aBtn.length);
   // aBtn.click(function(){$('html,body').animate({scrollTop:$('.1').offset().top}, 800);}); 
       aBtn.each(function(i){
           $(this).click(function(){
               $('html,body').animate({scrollTop:$('p[class = i ]').offset().top}, 800);
           });
       });

As above, I want to correspond i in each() to p with class i, but writing $('p[class = i]') like this is not possible. Please find a solution

PHP中文网PHP中文网2710 days ago432

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-05-19 10:14:02

    will$('p[class = i ]') 替换为$('.' + i)

    reply
    0
  • Cancelreply