An easier way would probably be to use a function. Try putting something like this in your JavaScript:
if (typeof window.customScripts == 'undefined') {
window.customScripts = {};
window.customScripts.createImg = function (source, imgClass, imgID, imgAlt, location) {
var $buildImage = $(document.createElement('img'));
$buildImage
.attr({
id : imgID,
src : source,
class : imgClass,
alt : imgAlt
})
.appendTo(location);
}
}
Then, in passage:
<span class='imgWrapper'></span> <!-- the image will be placed in this span -->
<script>customScripts.createImg('http://url/to/image.jpg', 'imageClass', 'imgID', 'alt-text', '.imgWrapper')</script>
You can pass variables to the function as well:
(set: $url to 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQysBzwvD-cJTJWFhUDyfvQ-YvKX5gHFw8_IXSujo9DGG9RrrmJ')
<span class='imgWrapper'></span>
(print: "<script>customScripts.createImg('" + $url + "', 'imageClass', 'imgID', 'alt-text', '.imgWrapper')</script>")
<!-- note all the quotes around the variables -->
Move all your styling into your stylesheet if you use this function--though even if you decide not to use this function or something like it, you should still put the style rules in your stylesheet instead of having them gum up your HTML.