1

Fairly simple, I need to know if a custom image has been added to overwrite the default, and if it has to get its url.

(The custom image will always be added via inline style)

I'm ok with parsing the url out of the property, I just need to only get this if it's inline.

Update

I have an idea that I didn't want to propose at first to keep all ideas on the table.

I check the element for `.indexOf("background-image") after getting .attr('style') and if this !== -1 then I get .css('backgroundImage') and parse the url out with regex.

I'm just not convinced this is the best solution, but it is working.

5
  • Did you mean an image as a background? Commented Feb 16, 2013 at 7:59
  • Well, I have something slightly jury rigged working. I check the .attr('style') for indexOf background-image, and if it isn't -1 I get the .css('backgroundImage') and parse the URL with a regex. Commented Feb 16, 2013 at 8:03
  • Whats wrong with the solution you just described? You're looking for something simpler? Commented Feb 16, 2013 at 8:08
  • @WillNelson Yeah, I'm questioning whether it's a good approach for this. It might be the best way to go, I'm just not convinced. Commented Feb 16, 2013 at 8:09
  • I was just about to propose the solution you just described. I recommend adding that to your question. You're really asking if there's a better way than your current one. Commented Feb 16, 2013 at 8:10

1 Answer 1

2

You could:

var elem = $("div");

if(elem.attr("style").search("background-image") > -1){
   console.log(elem[0].style.backgroundImage)
}

Fiddle: http://jsfiddle.net/uJ3Nm/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.