Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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?)

like image 397
Vasily A Avatar asked Oct 20 '22 17:10

Vasily A


1 Answers

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

enter image description here

like image 118
Derek 朕會功夫 Avatar answered Oct 23 '22 13:10

Derek 朕會功夫