'jquery to vanilla js ( I have a code which is about clipboard thing )
I have a code written on jquery.
From https://gist.github.com/nicohaemhouts/0fa3ea89cad0b7d77648
This code is about pasting multiple line into input in html.
if (window.clipboardData) {
$('input[type=text]').on('paste', function (e) {
e.preventDefault();
$(this).val(window.clipboardData.getData('Text').replace(/(\r\n|\n|\r)/gm, " "));
});
}
clipboardData on first line is not existing in pure js.
Also, I can not understand Fourth line about jquery.
Can you please translate that jquery?
Solution 1:[1]
$(this).val(window.clipboardData.getData('Text').replace(/(\r\n|\n|\r)/gm, " "));
$(this) refers to the input field element that caused this paste event, .val is used to set its value as the content of the clipboard, but before setting the value all newline symbols (\n) and carriage return symbols (\r) are replaced with space using .replace.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Samuel Olekšák |
