Home > Back-end >  Changing variable count on html script
Changing variable count on html script

Time:01-04

Everytime I click a button I try to add 1 to a count variable and that changes the iframe link to its selected number:

                const number = document.getElementsByClassName("nextepisode")
                const count = 1;
    
                number.addEve = function() {
                    count = 2
                    number.innerHTML = count
                }
    
                <iframe id="iframe" src="https://www.2embed.ru/embed/tmdb/tv?id=1421&s=1&e=${count}" width="100%" height="100%" frameborder="0"></iframe>
    
                function prepareFrame () {
                    const ifrm = document.createElement("iframe")
                    ifrm.setAttribute("src", `https://www.2embed.ru/embed/tmdb/tv?id=1421&s=1&e=${count}`)
                    ifrm.style.width = "800"
                    ifrm.style.height = "600"
                    ifrm.allowFullscreen = true
                    ifrm.allow = "autoplay"
                    ifrm.scrolling = false
                    ifrm.frameBorder = "0"
                    document.body.appendChild(ifrm)
                }
    <body>
        <div style="text-align:center">
            <button><a >Next Episode⏭</a></button>
    
        </div>
    </body>
    </html>

It just shows a blank screen, I'm kind of new to JavaScript so this may be something simple.

CodePudding user response:

const number = document.getElementById("nextepisode")
let count = 1;

const ifrm = document.createElement("iframe")
ifrm.setAttribute("src", `https://www.2embed.ru/embed/tmdb/tv?id=1421&s=1&e=${count}`)
ifrm.style.width = "800"
ifrm.style.height = "600"
ifrm.allowFullscreen = true
ifrm.allow = "autoplay"
ifrm.scrolling = false
ifrm.frameBorder = "0"
document.body.appendChild(ifrm)

function changeNumber() {
    count  = 2
    ifrm.setAttribute("src", `https://www.2embed.ru/embed/tmdb/tv?id=1421&s=1&e=${count}`)
    console.log(number)
    number.innerHTML = count
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
  </head>
  <div style="text-align:center">
    <button onClick='changeNumber()'>Next <span id="nextepisode"></span></button>
  </div>
</html>

  •  Tags:  
  • Related