Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6026889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:30:39+00:00 2026-05-23T04:30:39+00:00

I am setting the background-image of some elements using css (some elements have no

  • 0

I am setting the background-image of some elements using css (some elements have no background image)

.file-type-pdf {
    background-image: url("file-type-pdf.png");
}

I am then trying to determine in javascript whether certain elements have a background image or not, as follows

var style = YAHOO.util.Dom.getStyle(el, 'background-image');
console.log(style);

This works perfectly in FF, where elements with no background image return ‘none’ and elements with a background image return the image url.

However, in chrome and safari, the same code returns an empty string for both cases.

If i were to set a background image in the javascript code as follows, chrome and safari then return the image url ‘foo.jpg’ correctly

YAHOO.util.Dom.setStyle(el, 'background-image', 'url("foo.jpg")');
var style = YAHOO.util.Dom.getStyle(el, 'background-image');
console.log(style);

However, I cannot work out why these browsers cannot access the background-image set through the css

Note also that this syntax (maybe more familiar to some) is producing the same results (empty string in webkit browsers but correct on FF)…

var style = window.getComputedStyle(el, null) || el.currentStyle;
console.log(style.backgroundImage);

Any help would be much appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:30:40+00:00Added an answer on May 23, 2026 at 4:30 am

    This works fine for me on the Stack Overflow logo using the Chrome console on this page.

    For vanilla JS:

    var logo = document.getElementById("hlogo").childNodes[1];
    getComputedStyle(logo).getPropertyValue('background-image');
    

    For jQuery:

    $("#hlogo a").css("backgroundImage")`
    

    For YUI:

    // You have to load YUI first.
    var logo = document.getElementById("hlogo").childNodes[1];
    YAHOO.util.Dom.getStyle(logo, 'background-image');
    

    All return "url(http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3)".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to put some background image for TableView row cell. I am using
I am setting an image as a background inside a DIV and and want
I am trying to create a CSS layout where the page looks like it's
OKAY! Here's the situation. I've got a jQuery plugin that's animating a background-image in
Does anyone know if there is a php library, or if there isnt, have
I am getting strange aliasing behaviour in a WPF app using FluidKit's ElementFlow control.
I have a <div> on a webpage which ends up with a calculated height
Every time I design websites in Photoshop, I slice up the elements I want
I am building some basic HTML code for a CMS. One of the page-related
So far, I only have a div that would contain this information. As for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.