Colmjude

Notes

A collection of TILs, snippets and thoughts
<< Back to notes

Huffduffer input copying

Last updated 09 May 2020

Huffduffer has a nice little feature that helps a user copy some content. It puts the content in a input element and selects the whole lot when the user clicks on it.

It is an enhancement, done with JS.

An event listener waits for a click, checks if the input has a readonly attribute and then selects the whole contents of the input. E.g.

this.$module.addEventListener('click', function (ev) {
    var target = ev.target
    if (target.hasAttribute('readonly')) {
        target.focus()
        target.select()
    }
})
Tags
frontend / js