1

I have a function that creates an image with the canvas object. The last line of the function says this:

$('body').css({ 'background-image': "url(" + Canvas.toDataURL("image/png") + ")" });

I'm looking to convert this line into pure javascript to remove the jQuery dependency. Any suggestions?

Thanks.

1 Answer 1

6
document.body.style.backgroundImage = 'url('+Canvas.toDataURL('image/png')+')';
Sign up to request clarification or add additional context in comments.

2 Comments

Don't forget that IE doesn't like style, and uses cssText.
I've never had any issue with IE and .style.property. quirksmode.org/dom/w3c_css.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.