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

237
Views
Javascript - Retrieve background image url is null

I want to retrieve background image from this link https://20.detik.com/sosok/20220108-220109036/tangis-rindu-pak-ogah-pada-pak-raden but the output is null

<div class="vjs-poster" tabindex="-1" aria-disabled="false" style="background-image: url(&quot;https://cdnv.detik.com/videoservice/AdminTV/2022/01/08/Tangis_Rindu_Pak_Ogah_Pada_Pak_Raden-20220109001335-custom.jpg?w=400&amp;q=80&quot;); background-color: black; background-size: contain;"></div>

here is my code

    var c = document.createElement("html");
    c.innerHTML = content;
    body = c.getElementsByTagName('body')[0];

    //get poster url
    filmimg = body.getElementsByClassName("container-video")[0];
    div = filmimg.querySelector("div #detikVideoIdNewId video .vjs-poster");
    console.log(div);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try computedStyle

const style = window.getComputedStyle(
  document.querySelector(".vjs-poster")
)
console.log(style["backgroundImage"])
<div class="vjs-poster" tabindex="-1" aria-disabled="false" style="background-image: url(&quot;https://cdnv.detik.com/videoservice/AdminTV/2022/01/08/Tangis_Rindu_Pak_Ogah_Pada_Pak_Raden-20220109001335-custom.jpg?w=400&amp;q=80&quot;); background-color: black; background-size: contain;"></div>

about 4 years ago · Juan Pablo Isaza Report

0

Looks like your querySelector is off. Try this:

let backgroundImage = document.getElementsByClassName("vjs-poster")[0].style["background-image"];
let url = backgroundImage.split("\"")[1];
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!