def paste_js(clipboard):
    """Paste the string ``clipboard`` into the selected text of the focused
    element in the DOM using JavaScript/jQuery.
    """
    return (
        f"var focused = document.activeElement;\n"
        f"var start = focused.selectionStart;\n"
        f"var end = focused.selectionEnd;\n"
        f"var val = focused.value;\n"
        f"var new_val = val.slice(0, start) + `{clipboard}` + val.slice(end, val.length);\n"
        f"focused.value = new_val;\n"
        f"var cursorPos = start + `{clipboard}`.length;\n"
        f"focused.setSelectionRange(cursorPos, cursorPos);"
    )