crazyghandi crazyghandi - 1 month ago 25
CSS Question

js/css add multiple backgrounds

i have seen several usages of the .css() function or simply setting element.style.background in js

what i want is to stack multiple backgrounds, ie add another background over the 1st one.

i tried input.style.background.add("white url('http://cssdeck.com/uploads/media/items/5/5JuDgOa.png') no-repeat 30px 6px;");

but the add function is not recognized : TypeError: input.style.background.add is not a function

i guess i could set the css after onload with "background1", then reset it as "background1, background2" and back to "background1" when i need to but i would prefer an add() / remove() approach

Answer

why not create a few classes :

.bg-1{bg-img ...1}
.bg-2{bg-img ...2}

and use

.addClass('bg-1');

and

.removeClass('bg-x');

etc... with a js function with the wanted delay

Warning :

Jquery functions apply to jquery objects, for you :

$(input).addClass('some-class');