Step 1 retrieve id from button
Step 2
duplicate contents in td for the same id
Access the code on Codepen: https://codepen.io/terecal/pen/LoxmbP?editors=1010
$(".copy_code").click(function(e){
e.preventDefault();
var id = this.id
alert("id : ", id)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td>code</td>
<td colspan="122" id="my_code_122"> hello world </td>
</tr>
</table>
<button type="button" name="button" id="122" class="copy_code">copy</button>
Is it possible?
p.s
I implemented your technique.
The provided code is functioning correctly
`
$(".copy_code").click(function(e){
e.preventDefault();
var id = $(this).attr('id')
alert("id : " + id)
var text = document.getElementById(id),
textVal = text.innerText;
textTd = $(`#my_code_${id}`).text()
alert("copied code " + textTd) // textVal code copy
// I want to replicate this content as if copying with ctrl + c. Is that achievable? Appreciate your guidance.
});
`
The issue is almost resolved.
I simply aim to copy the retrieved text as though pressing ctrl + C
Could you assist me with achieving this?
ps2
The current code snippet looks like this
$(".copy_code").click(function(e){
e.preventDefault();
var id = $(this).attr('id')
alert("id : " + id)
var text = document.getElementById(id),
textVal = text.innerText;
textTd = $(`#my_code_${id}`).text()
alert("copied code " + textTd) // textVal code copy
// I want to replicate this content as if pressing ctrl + c. Is there a way? Thank you if you let me know.
var dummy = document.createElement('textarea');
dummy.value = textTd;
document.body.appendChild(dummy );
dummy.select();
document.execCommand('copy');
document.body.removeChild(dummy);
alert("copied code2 " + textTd)
});
and the copying feature works fine
but after pasting with ctrl + v
the new line (br) does not function ^^;;
original:
from django.contrib import admin
from django.urls import path, include
from . import views
app_name= 'css_challenge'
urlpatterns = [
]
copy:
from django.contrib import adminfrom django.urls import path, includefrom . import views
app_name= 'css_challenge'urlpatterns = [
]
Is it possible to maintain line breaks upon copying??