Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the Document</title> </head> <body> <input id="inputId" style="width:200px" value="Select here and click the button"> <button id="buttonId">Selection in stars /*...*/</button> <script> buttonId.onclick = () => { if(inputId.selectionStart == inputId.selectionEnd) { return; // nothing is selected } let selected = inputId.value.slice(inputId.selectionStart, inputId.selectionEnd); inputId.setRangeText(`/*${selected}*/`); }; </script> </body> </html>