Hey! Do you have any query related to front end?

Sign in Sign up

Select all text on single clickBack


Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Code: Copy and paste

//Get dom element as per your choice
var selectableCon = document.getElementsByClassName('selectableCon')[0];

//Take a variable to represent the state of selection
var selectStat = false;

//Set on click event for the DOM
selectableCon.onclick = function(){

	//Set DOM to contentEditable = true to true otherwise.
	this.contentEditable = true;

	//Use execCommand that will execute selection command
	document.execCommand('selectAll', false, null);

	//Set contentEditable to false otherwise user can edit
	this.contentEditable = false;

selectableCon.onblur =function(){
	this.contentEditable = false;
	selectStat= false;

How to comment:

  • Create an account in discuss by clicking on login next to arrow.
  • Create password for discuss and varify your email id, through your mail.
  • Refresh page and comment.

You might also like

  • Before and after vs empty tag

    Adding before and after to an non container element is no possible.

    • 7
    • 1
    • 7
    • facebook icon
    • twitter icon
    • google plus
  • Smooth parallaxt effect on mouse move

    Very smooth parallax effect on mouse movement

    • 373
    • 6
    • 373
    • facebook icon
    • twitter icon
    • google plus
  • Centralize your content

    Position your content according to your choice

    • 266
    • 5
    • 266
    • facebook icon
    • twitter icon
    • google plus

Latest quries posted

gopa kumarabout 3 years ago

amit singhabout 3 years ago

rahmat aliabout 3 years ago

mandavi tiwariabout 3 years ago

rahul sharmaabout 3 years ago

Ask question
Latest video
Learn Angular
Profile pic
Guest Back