javascriptselection-api

'selectionStart' property exists (?) but cannot be accessed


In my simple bookmarklet, I call all input elements of the document, and then try to try to access selectionStart of each element:

javascript: (function () {
 var inps=document.getElementsByTagName('input');

 for (var i = 0; i < inps.length; i++) {
   var el = inps[i];
         if ('selectionStart' in el) {
           console.log("o: " + (typeof el));
           console.log("x: " + (typeof el.nonexistent));
           console.log("s: " + (typeof el.selectionStart));
         }
 } 


})();

this code gives the following lines in the console: "o: object" - as expected, "x: undefined" - as expected, but for el.selectionStart no output is given and "NS_ERROR_FAILURE" is shown in the console. Can anybody explain why does this happen? (additional general question - where can I find the meaning or any details about such errors thrown by Firefox?)


Solution

  • You can not access selectionStart of a type hidden element, or even type button: http://jsfiddle.net/DerekL/pbCnQ/

    enter image description here