Home > Back-end >  wrap selected text inside div in stars vuejs
wrap selected text inside div in stars vuejs

Time:03-22

Hello everyone I'm trying to wrap the selected text inside a text area between 2 stars Entry would be for example vuejs => ** vuejs ** . Though I didn't figure out how to make the selected text wrapped with stars only.

    //this is my text area object
    <textarea  id="textAreaExample3" rows="4" placeholder="taper 
    votre texte" ></textarea>
    //this is the method that gets triggered on a button click when the text gets selected
    makeSelectedTextBold(){
    let text = document.getElementById('question').innerText;
    // selected text
    let selection = window.getSelection().anchorNode.data;
    console.log(selection)
    // wrap text to be shown on button click (I couldn't figure this out can someone help me)
   
    },

CodePudding user response:

I don't quite understand what you're trying to do. Make ALL the text in the text area bold, or make the text appear in a console log in bold?

CodePudding user response:

This will help with the HTML:

<button id="button" onclick="makeSelectedTextBold()">here<button>
<textarea  id="textAreaExample3" rows="4" placeholder="taper votre texte" ></textarea>

This will help with the JS:

document.getElementById("button").addEventListener("click");
function makeSelectedTextBold(){
    let text = document.getElementById("textAreaExample3").value;
    console.log("text:"   text)
    let selection = window.getSelection();
    console.log("selection:"   selection)
 }    

And this should help with finding and replacing the text: Find and Replace for an Textarea

  • Related