change focus into particular div

前端 未结 2 1297
小蘑菇
小蘑菇 2020-12-01 10:49

how can i change focus into particular div after any event via jquery?

相关标签:
2条回答
  • 2020-12-01 11:12

    Use $(window).scrollTop() It'll scroll the window to the particular item.

    Here is the example

     var scrollPos =  $(".focusme").offset().top;
     $(window).scrollTop(scrollPos);
    
    0 讨论(0)
  • 2020-12-01 11:14

    To make a div focusable, it needs to have a tabindex attribute.

    <div id='test' tabindex='1'></div>
    

    Then, you can focus with e.g.

    $('#something').click(function() {
      $('#test').focus();
    });
    
    0 讨论(0)
提交回复
热议问题