focus-events.html (1283B)
1 <!DOCTYPE html> 2 <meta charset=utf-8> 3 <title>Focus management</title> 4 <link rel="author" title="Denis Ah-Kang" href="mailto:denis@w3.org"> 5 <link rel=help href="https://html.spec.whatwg.org/multipage/#focus-management"> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <div id="log"></div> 9 <input type=text id=i1> 10 <input type=text id=i2> 11 <script> 12 var i1 = document.getElementById('i1'), 13 i2 = document.getElementById('i2'), 14 t1 = async_test("focusing on a focusable element fires a focus event at the element"), 15 t2 = async_test("focusing on a focusable element fires a blur event at the previous focussed element"); 16 17 i2.onfocus = t1.step_func_done(function(e){ 18 assert_true(e.isTrusted, "focus event is trusted"); 19 assert_false(e.bubbles, "focus event doesn't bubble"); 20 assert_false(e.cancelable, "focus event is not cancelable"); 21 assert_equals(document.activeElement, i2); 22 }); 23 24 i1.onblur = t2.step_func_done(function(e){ 25 assert_true(e.isTrusted, "blur event is trusted"); 26 assert_false(e.bubbles, "blur event doesn't bubble"); 27 assert_false(e.cancelable, "blur event is not cancelable"); 28 assert_equals(document.activeElement, document.body); 29 }); 30 31 i1.focus(); 32 i2.focus(); 33 </script>