selecting all text within a div on a single left click with javascript
- by tstyle
I have a simple non-clickable link within a div that looks like this:
It's meant to be a sharable link that the user can copy paste into other things.
For usability purposes, I want a single left click anywhere within the div to select the entire link:
I don't know much about, javascript/web programming, so I've tried the following:
<div id="share_link" onClick="select_all('share_link')"><%= request.url %></div>
and this javascript
<script type="text/javascript">
function select_all(id) {
document.getElementById(id).focus();
}
</script>
This doesn't work. I'd like to know what's the simplest thing I should do to achieve what I want. I thought about changing the div to a text input or the text within to be a link, but ideally the content within should be read-only, non-editable, and non-clickable