Hi, sorry to hear you got the attack screen.
My img element has an inline style with padding and border defined. So like you said, it should work.
Here is the html
HTML Code:
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
</head>
<body>
<p>Paragraph</p>
<img
style="padding:10px; background-color:lightgrey; border:green solid;"
title="Title Caption"
alt="Alt Caption"
class="captionImg" src="http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif" />
<p>Another Paragraph</p>
</body>
</html>
CSS...
HTML Code:
.imgWrapper {
background-color:yellow;
}
.captionImg {
}
.imgCaption {
padding:0px;
background-color:orange;
border:black solid;
}
and jQuery...
Code:
$('img[alt]').each(function() {
var img = $(this);
// create the wrap div
var theWrap = $('<div class="imgWrapper"></div>');
// add the wrap div to the DOM
$(img).after(theWrap);
var captionText = img.attr('alt');
var style = $(this).css("padding");
// put the content into the wrap div
$(theWrap).append(img);
$(theWrap).append('<br /><span class="imgCaption" style="padding:' + style + '">' + captionText + '</span>');
// I was trying different things here...
//$(".imgCaption").css("background-color", $("img").css("background-color") );
//$(".imgCaption").css("border", $("img").css("border") );
Thanks
Bookmarks