I have a bunch of Javascript functions that look like the following:
function generateBusinessImage (business) {
var business_image = document.createElement('img');
business_image.setAttribute('class','photo');
business_image.alt = business.name;
business_image.title = business.name;
business_image.align = 'right';
business_image.src = business.photo_url;
return business_image;
}
This seems like a good canidate for a refactor. From reviewing a few different jQuery docs, it would appear that I should be able to do something similar to this pseudo code:
return var business_image = document.createElement('img').
setAttribute('class','photo').
alt(business.name).
title(business.title).
align('right').
src(business.photo_url);
Am I on the right track?
Thanks!
EDIT
I'm calling the function above with the following code and the line where I do appendChild on div with generateBusinessImage is where my errors are occurring with some of the answers below:
var div = document.createElement('div');
var div_class = document.createAttribute('class');
div.setAttribute('class','business');
div.appendChild(generateBusinessImage(business));