- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Match the style of element while performing paste - jQuery?
For this, use <pre> tag. Set it to contenteditable −
<pre id="data" contenteditable></pre>
We have set the following style for paste −
<style> pre { min-height: 150px; min-width: 300px; font-family: 'Times New Roman', Times, serif; white-space: pre; background-color: rgb(19, 22, 27); color: #98d8e7; } </style>
Now, you can use paste event listener −
var getTheData = document.getElementById('data'); getTheData.addEventListener('paste', PutTheDataOnEditor);
Example
Following is the code −
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> <script src="https://code.jquery.com/jquery-1.12.4.js"></script> <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> <style> pre { min-height: 150px; min-width: 300px; font-family: 'Times New Roman', Times, serif; white-space: pre; background-color: rgb(19, 22, 27); color: #98d8e7; } </style> <body> <pre id="data" contenteditable></pre> </body> <script> function PutTheDataOnEditor(event) { event.preventDefault(); const textData = event.clipboardData.getData("text"); event.target.innerHTML = textData; console.log(textData); } var getTheData = document.getElementById('data'); getTheData.addEventListener('paste', PutTheDataOnEditor); </script> </html>
Output
The output is as follows −
Now, I am going to copy and paste some value from notepad to this editor.
Output
The output is as follows −
Output
The output is as follows −
- Related Articles
- How to get a style property on the matched element using jQuery?
- What is the use of MySQL BINARY keyword while performing string comparison?
- Performing different SAP logon check while connecting to HANA
- The order of the whole numbers does not matter while performing the addition operation. Why ?
- Match element in array of MongoDB?
- jQuery element Selector
- Style every element that is the first element of its parent with CSS
- Style every element that is the last element of its parent with CSS
- Style every element that is the nth element of its parent with CSS
- Style every element that is the only element of its parent with CSS
- How to apply CSS style using jQuery?
- jQuery element + next Selector
- jQuery element ~ siblings Selector
- Style every element that is not the specified element with CSS
- How to remove all style attributes using jQuery?

Advertisements