Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
this is the html code :

<div class="Winter">

</div>


right now i have not get background image.


this is the css code :

CSS
.Winter{
	background: no-repeat center bottom scroll;
	background-image:;	
	width:410px;
	height:410px;
	float:left;
	margin-top:20px;
	margin-left:5px;
}


i dont set a backgourd image because i use in this to change the background :

<script src="http://code.jquery.com/jquery-1.11.0.min.js">
$(document).ready(function(){
var Winter = $('body');

var backgrounds = new Array(
, 'url(img/winter/earwarmers/9.jpg)'
, 'url(img/winter/hats/7.jpg)'
, 'url(img/winter/jacket/4.jpg)'
);

var current = 0;

function nextBackground() {
current++;
current = current % backgrounds.length;
Winter.css('background-image', backgrounds[current]);
}
setInterval(nextBackground, 1000);

Winter.css('background-image', backgrounds[0]);
});
</script>

now i ask this :

i dont have background image
but i want background image so how can i change the background image from the html page that in the css page it change?

and how can i do that thr image go in loop in javascript or jquery?

help me plz

What I have tried:

i try to change the div class to id and set get by element id but noyhing change
Posted
Comments
Sinisa Hajnal 7-Apr-16 4:33am    
You didn't change the background of your div element, but of body element.
var Winter = $('body') returns body of the page. You should try $('.Winter').

Also, it is common to use lower case names in CSS (i.e. winter)
jaket-cp 7-Apr-16 6:27am    
Sinisa, by any chance to you have a reference link where it states the common use of lower case for css class names.
If you know of a pros-cons link that would be good.
As I on the whole use PascalCase for css class naming.
thanks
jaket-cp 7-Apr-16 5:20am    
Also populating backgrounds array - extra [comma] needs to be removed.
https://jsfiddle.net/5oty8wvb/
komokom 7-Apr-16 5:45am    
ohhhhhhhh nice one dude thank you for the solution its working ty ty
jaket-cp 7-Apr-16 6:25am    
glad to help
also have a look at
https://jsfiddle.net/5oty8wvb/1/
https://jsfiddle.net/5oty8wvb/2/
to see how the code can be mixed about.
Play around with them to made improvements for code re-use.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900