Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Good Example: Focus moved to AJAX content with tabindex="-1" after a delay

<div id="decContainer"></div>
<script>   
$("#decButton").click(function(){
  $.ajax({
    url: "assets/html/module-dynamic/ajax/declaration.html", 
    type:'GET',
    cache: false,
    success: function(result){
      $("#decContainer").show().html(result);
      var decHeading = $("#decContainer h2:first");
      /* set tabindex="-1" so the heading can receive keyboard focus */
      decHeading.attr('tabindex','-1');
      setTimeout(function(){ 
        /* move focus to the heading after a delay of 1 second */
        $("#decContainer h2:first").focus(); 
      }, 1000);
    }
  });
}); 
</script>
Source by dequeuniversity.com #
 
PREVIOUS NEXT
Tagged: #Good #Focus #moved #AJAX #content #delay
ADD COMMENT
Topic
Name
9+7 =