Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
JS Button to toggle youtube embedded video

So I made a toggle button with JS functionality inside elementor plugin. When button clicked for the first time, the embedded video will play. When clicked after that, it'll pause. And when clicked again, it'll play again. And so on. Here's the code I've written:


const vid1 = document.getElementsByClassName("eicon-play")[0];
let santanVid = 'pausing';

document.getElementById("santan-thumb").onclick = () => {
    
    if (santanVid = 'pausing') {
        santanVid = 'playing'
    } else if (santanVid = 'playing') {
        santanVid = 'pausing'
    }
    
    if (santanVid = 'pausing') {
        vid1.click();
        $('.elementor-video')[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*')
    } else if (santanVid = 'playing') {
        vid1.click()
        $('.elementor-video')[0].contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*')
    }
};

The problem is, it only worked once. The first time I load the page, click the button and the video will play. Click the button the second time, and the video stop. But if I clicked again, the video won't play

I've tried using 2 button and the code is working, the problem occurs when I'm using 1 button as a toggle, and I'm curious how to make it possible that way.

Thank you before!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your if statements you are assigning values, not checking. To check use double or triple equal signs (==) or (===)

Example: if(santanVid === 'pausing')

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!