disable text selection in js 1

disable text selection in js

onselectstart = (e) => {
  e.preventDefault()
  console.log("nope!")
  }

Here is what the above code is Doing:
1. We’re creating a function called onselectstart.
2. We’re passing in an event object called e.
3. We’re calling the preventDefault() method on the event object.
4. We’re logging a message to the console.
5. We’re returning false.
6. We’re assigning the function to the onselectstart property of the document object.

The onselectstart property is an event handler that fires when a user tries to select text on a page.

The preventDefault() method prevents the default behavior of an event from happening. In this case, it prevents the user from selecting text on the page.

The return false statement at the end of the function prevents the default behavior of the event from happening.

The last line of code assigns the function to the onselectstart property of the document object.

The document object represents the web page that the browser is displaying.

The onselectstart property is an event handler that fires when a user tries to select text on a page.

The preventDefault() method prevents the default behavior of an event from happening. In this case, it prevents the user from selecting text on the page.

The return false statement at the end of the function prevents the default behavior of the event from happening.

The last line of code assigns the function to the onselectstart property of the document object.

The document object represents the web page that the browser is displaying.

Similar Posts