Accessibility/WebAccessibilityAPI: Difference between revisions

Line 876: Line 876:
</code>
</code>


<b>Example. Traverse a paragraph by words.</b>
<pre>
var p = document.getElementById("p").a11ement;
var pos1 = new A11ePos(p, "afterbegin"), pos2 = null;
while (pos2 = pos1.search("forward", () = > { return "word"; })) {
  console.log(pos2.textInBetween(pos1));
  pos1 = pos2;
}
</pre>
<pre>
<p>Mozilla is a <a href="">free-software</a> community which
produces the <a href="">Firefox web browser</a>.</p>
<p>Mo<a href="">zilla</a>.</p>
</pre>
the log is "Mozilla ", "is ", "a ", "free-", "software ", "community", "which ", "produces ", "the ", "Firefox ", "web ", "browser."
The log is "It ", "is ", "Mozilla".


<b>Examples.</b>
<b>Examples.</b>
Line 902: Line 923:
   var role = document.taxonOf("role", aEl.role);
   var role = document.taxonOf("role", aEl.role);
   if (role.is("widget")
   if (role.is("widget")
     return [ "at", "skipsubtree" ];
     return [ "beforeend" ];


   if (role.is("structure")
   if (role.is("structure")
Confirmed users
1,396

edits