Tinymce doesnt work when I write html with InnerHtml in JS script

Viewed 14

Tinymce doesnt see ID of textarea and doesnt init, when I load the content in body function onload! Id is correctly! Tynimce init in

<head th:insert="~{/toInsert/head.html}">
  <!-HERE INIT TyniMce-->
    <title>Admin Panel</title>
</head>
<body onload="getBlogById()">
function getBlogById() {
            const res = new XMLHttpRequest()
            let blogId = document.location.href.split("/").pop();
            res.open("GET", "http://localhost:8000/blogs/" + blogId)
            res.send()
            res.onload = function () {
                let blog = JSON.parse(this.responseText)
                const resGames = new XMLHttpRequest()
                resGames.open("GET", "http://localhost:8000/games")
                resGames.send()
                resGames.onload = function () {
                    let allGames = JSON.parse(resGames.responseText)
                    const resStatus = new XMLHttpRequest()
                    resStatus.open("GET", "http://localhost:8000/blogStatus")
                    resStatus.send()
                    resStatus.onload = function () {
                        let allStatus = JSON.parse(resStatus.responseText)
                        let content = ""
                        
                        if (blog.blogStatus.blogStatusName == "IN WAITING") {
                            content += "<textarea rows='10' id='tinyMceTextarea' class='form-control' name='blogDescription'>" + blog.blogDescription + "</textarea>"
                        } else {
                            content += "<textarea rows='10' id='tinyMceTextarea' class='form-control' name='blogDescription' readonly>" + blog.blogDescription + "</textarea>"
                        }
                        document.querySelector(".blogInfo").innerHTML = content
                    }
                }
            }
        }
</body>

enter image description here

0 Answers
Related