Nilzor
Nilzor

Reputation: 18603

Any way to make double click select more than one word without Javascript?

Let's say I have a web page which contains command line commands for the user to copy paste. Any way to display it with HTML/CSS which makes double clicking on one word select the entire command?

Example: ls -l /myfiles - clicking on "myfiles" here selects only that word, but for the user it'd be a better experience if the entire command was selected for easier copy-pasting. Again: No javascript is the question here.

Upvotes: 5

Views: 2357

Answers (4)

hermlon
hermlon

Reputation: 304

Setting the CSS property user-select: all; would allow to select the whole element using a single click: https://www.w3schools.com/cssref/css3_pr_user-select.asp

Upvotes: 0

kasper Taeymans
kasper Taeymans

Reputation: 7026

I commented in the question that selecting multiple words by double clicking is not possible without javascript. This is not totally true at least for firefox. I just found a way that will select multiple words by double clicking the first word!

You need to use a space followed by unicode ‏ (right-to-left mark)

Only works in Firefox!

jsfiddle demo

OR double click 'Hello' in the block qoute for demo.

Hello ‏my ‏name ‏is ‏Kasper

I don't know why this is working. I was just experimenting with unicodes... More info can be found on w3.org:

Using a Unicode right-to-left mark (RLM) or left-to-right mark (LRM) to mix text direction inline

EDIT:

Using other unicode space characters may be closer to the behaviour you want. For example unicode   DEMO (jsfiddle) OR double click any word in the block quote below (again, only works in firefox)

Hello my name is Kasper

other example (double click on a word with capitals)

in this SENTENCE ONLY WORDS WITH capitals are selected

Upvotes: 4

Rémi Becheras
Rémi Becheras

Reputation: 15222

No there isn't any way to do that for a double click without javascript.

The default browser behavior is the only behavior available without javascript.

  • Tripple-click will works to select a single line.
  • If you want to select a different pattern, you need javascript.
  • If you only want this behavior on double-click, you need javascript.

Upvotes: 2

mvryan
mvryan

Reputation: 347

Would they be able to just triple click? You can select an entire element with that, or to limit it put in breaks.

This would keep expected highlighting behavior consistent.

Upvotes: 3

Related Questions