I have this code
document.querySelector('.code_gen').onfocus = function(e) {
var el = this;
requestAnimationFrame(function() {
selectElementContents(el);
});
};
Doesn’t work. I have three divs with the class .code_gen. However, if I change that class to a particular id of one of the divs, it works great for that particular div on focus.
How can I tell the function the class on focus and know to run the function against the div that is being focused with matching class?
The only working option I have is to repeat the function repeatedly, like so:
document.querySelector('#hd_div').onfocus = function(e) {
var el = this;
requestAnimationFrame(function() {
selectElementContents(el);
});
};
document.querySelector('#sd_div').onfocus = function(e) {
var el = this;
requestAnimationFrame(function() {
selectElementContents(el);
});
};
document.querySelector('#ld_div').onfocus = function(e) {
var el = this;
requestAnimationFrame(function() {
selectElementContents(el);
});
};
Trying to save some code. All those IDs/divs share the same class.
All feedback appreciated.
Cheers!
Ryan