Preload background | SoloLearn: Learn to code for FREE!


Preload background

I have a preloaded image in an image variable: var a=new Image() After that I can use the variable for drawing image: ctx.drawImage(a,x,y) But how can I change a background of TD using this variable and JQuery ? Is it possible ?

11/27/2018 9:11:48 AM

Алексей Васильев

6 Answers

New Answer


Perhaps create a CSS class instead, with a setting for background image, and then toggle the class in the <td> where you want? CSS class can be implemented to multiple <td> anyways : )


To be honest I only know preloaded images can be used for <img>, I never tried it for <td> background image, you meant a <td> of a <table> here? or am I misunderstanding you ...


Do you have that code here in your profile? can you attach the code URL on the original post, that way I hope others who knows better can help you with it. In the meantime I will try to search for a feasible solution.


Yes, for td in table. I try to work with images correctly but I don't know how.


My images are not in the same directory. They are far and I run the risk of trying to change the background BEFORE the image was loaded...


I will prepare it thank you)