+ 1
Copying something with a button
When I click to button , It will copy a div's innerHTML can I do that with html5 or javaScript ? -> ctrl + w / right click + copy / ...
11 Answers
+ 5
just so you know the copy you actually wanted to implement will always be implemented already by the environment e.g text editor, browser or operating system(linux, windows etc). The code above doesn't create the copy command but rather display success or failure message. Your image showing the dialogue menu for copy, cut etc are implemented by android environment.
+ 4
good research...đđ
+ 2
let btn = document. querySelector("button");
btn.addEventListener("click", function(){
// get div with content you want to manipulate
let txt = document.querySelector("div").innerHTML;
// now u can use "txt" above to control what to do with
the content or texts. e.g
// you could append another text to it
// output the text in another div...etc
})
+ 2
https://i.hizliresim.com/5QMWgD.jpg
that is my aim
+ 2
Wow! thought you wanted to learn, instead of upvoting you are thinking of making it your code...Lol. You may go ahead copy and use it OK. I didn't make it public it's your code. Happy coding!
+ 1
Thank you but I want that For example you wrote it for me and I copied it and than I pasted it to my own code
+ 1
you didn't understood đđđ could you look that -> https://i.hizliresim.com/5QMWgD.jpg
+ 1
I want to copy text button
+ 1
I found ->
<p>
<textarea class="js-copytextarea">Hello I'm some text</textarea>
</p>
<p>
<button class="js-textareacopybtn">Copy Textarea</button>
</p>
<script type="text/javascript">
var copyTextareaBtn = document.querySelector('.js-textareacopybtn');
copyTextareaBtn.addEventListener('click', function(event) {
var copyTextarea = document.querySelector('.js-copytextarea');
copyTextarea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
});
</script>
+ 1
Yes It isn't mine already I found it in stackoverflow so I didn't change it but while I using on my own project I will change I just wanted to learn đđđ
0
Actually , I don't understood sorry :( Could you write it and share with me ( I want to make "copy text" button )