How to get selection html in anki 2.1.42?

Hi. I have a question about javascript changes.
I wanna get selection with html tags such as ‘br’ in anki 2.1.42.

In 2.1.38, what I used before, this solution worked. (javascript)

function getSelectionHtml() {
    var html = "";
    if (typeof window.getSelection != "undefined") {
        var sel = window.getSelection();
        if (sel.rangeCount) {
            var container = document.createElement("div");
            for (var i = 0, len = sel.rangeCount; i < len; ++i) {
                container.appendChild(sel.getRangeAt(i).cloneContents());
            }
            html = container.innerHTML;
        }
    } else if (typeof document.selection != "undefined") {
        if (document.selection.type == "Text") {
            html = document.selection.createRange().htmlText;
        }
    }
    return html;
}

But, after I upgrade to anki 2.1.42., this solution is not working anymore.
It return nothing.

I miss something?

I’ve added a mention of getSelection on Add-on porting notes for Anki 2.1.41

1 Like

Thanks for reply!!
I try to review it.
Thanks.