I am trying to insert a background image into a header:before element, but jquery fails.
HTML content
<a href="image.jpg" class="image-source">Try insert image into .header:before</a>
JS
$('.image-source').click(function() {
var src = $(this).attr('href');
// slash is okay
$('.header:before').css('backgroundImage', 'url(/' + src + ')');
return false;
});
CSS:
.header {
position: relative;
background: url(anotherimage.jpg) no-repeat;
}
.header:before {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
margin:auto;
min-width:50%;
min-height:50%;
content: "";
}
Does anyone know if I am dealing with a bug here, or missed an obvious?
Note, I can not use .header
itself, because I am working with multiple background image, thats why I need :before
.
UPDATE: Might be this: