Let's say I have this html
<strong><a href="url">Link</a></strong>
and I want to replace this with something else programatically. I select this with the mouse and call
var sel = window.getSelection()
The content of sel
is however a text
, and its parentNode is the link node a
(and its parentNode is the <strong>
element I was looking for).
Can I get semantic elements like e.g. strong
, b
, em
in a selection?
Use case: I want to select some text in a wysiwyg editor (html) and replace it with a link.