0
Changing css value via Jquery
Is it possible to change the value of an element in css by using Jquery ? Something like that : Var img [ 'image1.png' 'image2.png' 'image3.png' ] var num = 0 button.addEventListener("click", function(){ container.style.backgroundImage = "url(???)"; // button = 'a' simple button here, and 'container' a simple div where the background change Been a long time since i've used Jquery can't remember how to do some things XD. Thanks for the help !!!
5 ответов
+ 3
Kevin Nguma
You cannot set multiple images like that.
You have to iterate array or object)
If it is array then:
for(var v in img) {
$('#divId').css('background-image','url(v)')
}
+ 3
Kevin Nguma
$('#divId').css('background-image','url(img/123.jpg)')
+ 1
What if i do something like that ?
$("#divid").css({
'background-image' : 'url(image1.png), url(image2.png), url(image3.png)'
});
+ 1
Ah ok!
THANK YOU 😁👍👍👍!!!
0
Many thanks !!!
But is there a way to make sure that when the button is pushed it changes the background-image value to the next (set in var img) ?
In fact, i would like to make it work like an image slider. with a "previous" and "next" button ...
Messy i know XD