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 !!!

25th Mar 2022, 2:12 PM
Sumpheus
Sumpheus - avatar
5 Answers
+ 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)') }
25th Mar 2022, 3:33 PM
A͢J
A͢J - avatar
+ 3
Kevin Nguma $('#divId').css('background-image','url(img/123.jpg)')
25th Mar 2022, 2:14 PM
A͢J
A͢J - avatar
+ 1
What if i do something like that ? $("#divid").css({ 'background-image' : 'url(image1.png), url(image2.png), url(image3.png)' });
25th Mar 2022, 2:54 PM
Sumpheus
Sumpheus - avatar
+ 1
Ah ok! THANK YOU 😁👍👍👍!!!
25th Mar 2022, 3:39 PM
Sumpheus
Sumpheus - avatar
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
25th Mar 2022, 2:48 PM
Sumpheus
Sumpheus - avatar