HTMLInputElement in IE7

Posted by Vladislav Qulin on Stack Overflow See other posts from Stack Overflow or by Vladislav Qulin
Published on 2012-09-11T09:35:59Z Indexed on 2012/09/11 9:38 UTC
Read the original article Hit count: 290

Filed under:
|

I'm writing an extension for crossbrowser input&textarea selection getter and setter. So that's the way i write my code:

HTMLInputElement.prototype.getSelectionRange = get_selection_range;
HTMLInputElement.prototype.setSelection = set_selection_range;
HTMLTextAreaElement.prototype.getSelectionRange = get_selection_range;
HTMLTextAreaElement.prototype.setSelection = set_selection_range;

get_selection_range and set_selection_range are those extended functions. So i just wanted to replace

someInputElement.selectionStart = a;  // and whole lot of code due to browser
someInputElement.selectionEnd = b;    // compatibility

with just

someInputElement.setSelection(a, b);
someInputElement.setSelection({ start: a, end: b });
someOtherElement.setSelection(someInputElement.getSelection());

But then i met couple of difficulties in IE7. First of all, IE7 doesnt know what is HTMLInputElement.

I don't want to extend whole Object. Well, that would be the last thing i'll do, but i want to evade it. Functions get_selection_range and set_selection_range are alright, don't ask what's within, you've seen it couple of times already.

So the question is: is there any legit substitution for HTMLInputElement in JS for IE7?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about dom