Colleen  Kitchen
Colleen Kitchen

Reputation: 1069

retrieving background image from div when dynamically set

I am having an issue with setting the background-image of a #x to the background image of #y.

Correct me if I am wrong but I think you would do this in a simple case by saying

$('#x').css('background-image',$('#y').css('background-image'));

The problem is that when y was initially set up, it was set up like this:

<div id='y' style='background-image: url(./randomcolor.php?ibase=<?php echo $entity->name; ?>) ....

So when it does it, it is getting the URL of the generator, and javascript is just regarding that as a string. Do I have to do an ajax get here, or is there some kind of eval I could use.

Upvotes: 1

Views: 1082

Answers (2)

Colleen  Kitchen
Colleen Kitchen

Reputation: 1069

http://forum.jquery.com/user/rickvhoeij provided the clue to answer this in the jquery forum. http://forum.jquery.com/topic/setting-background-image-to-another-div-s-dynamically-generated-image Actually the code isn't fine, when I changed background-image to camelCase (backgroundImage) then it started working. This is the kind bug I can never eyeball!! It just goes by, we are all so used to seeing that it's so easy to miss. Alconja, I appreciate your helpful probe questions. The answers would have been yes, the graphic displays OK in the first place, and everything else copies fine except that. and now I also realize that Firefox is not always Firefox. I started work on this in Linux and I moved to a Mac and Firebug looks a little different here. I assumed there weren't errors because FB wasn't flagging them the same way it does on Linux.

Duh! We are visual creatures of habit.

Upvotes: 1

Alconja
Alconja

Reputation: 14873

Your code looks fine.

The second part of your question doesn't make sense to me... Are you saying that your #x div ends up with a background image url of ./randomcolor.php?ibase=<?php echo $entity->name; ?> rather than the ./randomcolor.php?ibase=xyz that you'd expect. If so, you've got something going wrong with your PHP code. JQuery is just JavaScript, so it will only ever be dealing with client-side rendered HTML, if that HTML contains php tags, then the server side rendering of your page isn't doing its job.

Upvotes: 1

Related Questions