How to copy text or HTML to clipboard using JS/jQuery
Today we learn how to copy texts and html into the clipboard by using js, we can copy content on button click or any event through JS.
Here are the few simple methods for it. Please follow the below methods
HTML CODE
JQUERY CODE
Today we learn how to copy texts and html into the clipboard by using js, we can copy content on button click or any event through JS.
Here are the few simple methods for it. Please follow the below methods
1) Copy data-attribute value to clipboard
If you have an html element like a button with data value and you want to copy value on button click then use below functionHTML CODE
<a class="cls_copy_pg_action copyAction copy-action-btn" data-value="THIS TEXT WILL BE COPIED"> <i class="far fa-copy"></i> Copy</a>
JQUERY CODE
$(document).on("click", ".copy-action-btn", function() {
var trigger = $(this);
$(".copy-action-btn").removeClass("text-success");
var $tempElement = $("<input>");
$("body").append($tempElement);
var copyType = $(this).data("value");
$tempElement.val(copyType).select();
document.execCommand("Copy");
$tempElement.remove();
$(trigger).addClass("text-success");
});
The above code will copy the data into clipboard.
2) Copy INPUT field value on button click
HTML CODE<input type="text" value="THIS TEXT WILL BE COPIED" id="idInputField"> <button class="clsCopyBtn" onclick="copyFunction()">Copy Action</button>
JQUERY CODE
function
copyFunction()
{
var trigger = $(this); $(".copy-action-btn").removeClass("text-success"); var $tempElement = $("<input>"); $("body").append($tempElement); var copyType = $("#
idInputField
").val(); $tempElement.val(copyType).select(); document.execCommand("Copy"); $tempElement.remove(); $(trigger).addClass("text-success"); };
3) Copy to the clipboard using PURE JAVASCRIPT
If you dont want to use jQuery then you can do copy work with javascript too. Please
use below function
function
() { var copyInputContent = document.getElementById("
copyFunction
idInputField
");
copyInputContent
.select(); document.execCommand("copy");
}
4) Copy HTML of a HTML element
If you want to copy html of a HTML element like a div then you dont need to use clipboard . you can get html of element and save into a variable
Awsssmmmm post bro keep it up great work
ReplyDeletehttps://gajabwap.blogspot.com
Website Speed Optimization is using the strategies and techniques to speed up your site & make it faster to load in the web browsers. If your website loads slowly then you will lose your site rankings in search engine results. It requires a lot of efforts & tweaks to optimize your website speed. I have listed over 5 website speed optimization tips to increase your website speed. Moreover, you can use these techniques for both WordPress & Non-WordPress.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteYour Affiliate Money Making Machine is waiting -
ReplyDeletePlus, earning money online using it is as easy as 1..2..3!
Here are the steps to make it work...
STEP 1. Choose affiliate products the system will push
STEP 2. Add push button traffic (this ONLY takes 2 minutes)
STEP 3. See how the affiliate system explode your list and sell your affiliate products on it's own!
Do you want to start making money???
Click here to launch the system
Greate article and it's useful information. I have found the best collections
ReplyDeletePHP Interview Question. developers need to learn it
Node.js form validation
Upload Multiple file in Node.js
Node.js CRUD Operation
Autocomplete search in PHP
PHP Form Validation
Your article is very good. I'm following you.I understand exactly what you mean today. I had been to many blogs before but could not understand it. So I was very impressed when I read your article. Thank you very much for this.
ReplyDeletehi guys, if you want earn money in one day, so click here.
Online Friendship Club
Dating friendship
Free Online Dating Site
Online Dating
Matchmaker
Dating friendship
Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me.
ReplyDeleteweb designing course in chennai
Thanks for Sharing this Information. PHP Training Course in Gurgaon
ReplyDeleteHow To Clone Or Duplicate Html Element Using Jquery
ReplyDeleteLearn how to clone or duplicate html element using jquery.
For More Info:- How To Clone Or Duplicate Html Element Using Jquery
WanlitOgrat-ne Brian Thao click
ReplyDeletesmithasoblu
fratlasuffzaLas Vegas David Townes Speedify
ReplyDeleteDownload
PassFab Android Unlocker 2.5.2.6
Kaspersky AntiVirus
fitugwardvirb
betmatik
ReplyDeletekralbet
betpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
Y6KQ
شركة مكافحة حشرات في دبي IjvQDP8MRr
ReplyDelete