There is a table in which you need to select and copy two lines when you click on the button.
http://codepen.io/tews/pen/EPyyBJ
var copyNameBtn = document.querySelector('.copyname-btn'); copyNameBtn.addEventListener('click', function(event) { // ΠΡΠ±ΠΎΡΠΊΠ° ΡΡΡΠΎΠΊΠΈ ΠΈΠΌΠ΅Π½Π΅ΠΌ var nameStr = document.querySelector(".name"); var range = document.createRange(); range.selectNode(nameStr); window.getSelection().addRange(range); try { // Π’Π΅ΠΏΠ΅ΡΡ, ΠΊΠΎΠ³Π΄Π° ΠΌΡ Π²ΡΠ±ΡΠ°Π»ΠΈ ΡΠ΅ΠΊΡΡ , Π²ΡΠΏΠΎΠ»Π½ΠΈΠΌ ΠΊΠΎΠΌΠ°Π½Π΄Ρ ΠΊΠΎΠΏΠΈΡΠΎΠ²Π°Π½ΠΈΡ var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log('Copy email command was ' + msg); } catch(err) { console.log('Oops, unable to copy'); } // Π‘Π½ΡΡΠΈΠ΅ Π²ΡΠ΄Π΅Π»Π΅Π½ΠΈΡ // removeRange(range) ΠΊΠΎΠ³Π΄Π° ΡΡΠΎ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ window.getSelection().removeAllRanges(); }); Only the Name is copied, and it is necessary that when you click the name + surname is copied.
Those. Now when you press the button, only "Petya" is copied, but it is necessary that "Petya + Pupkin" be copied.
".name"+".patronymic"is it possible to do? ....... Your code is not working, by the way - Alexey Shimansky