I am trying to do a chrome extension that underlines specific words. Assume the user writes "hello" then I want to underline it. The thing that in Facebook and other social media the text field is a content editable div.
How can I access that text and manipulate only specific words inside it? I have tried doing this, but it didn't work
$('body').on('focus', '[contenteditable]', function() {
const $this = $(this);
$this.data('before', $this.html());
}).on('blur keyup paste input', '[contenteditable]', function() {
const $this = $(this);
if ($this.data('before') !== $this.html()) {
$this.data('before', $this.html());
$this.trigger('change');
if ($this.text().includes("hello")){
//document.execCommand('undeline'); //didn't work
//$this.style.textDecorationColor="red"; // neither did this
//$this.style.textDecorationStyle="wavy";
}
}
});
Note: I have tried document.execCommand
but it didn't give any results