Please help me I am new in jQuery. here is my code:
<img src="default.jpg" />
<img src="a.jpg" />
<img src="b.jpg" />
<img src="c.jpg" />
I want to change the picture from default.jpg to a.jpg. then a.jpg to to b.jpg and so on, every 5 seconds. using jquery. Thanks a lot
<img id="thisImg" alt="img" src="images/img0.png"/>
<script type="text/javascript">
$(function(){
//prepare Your data array with img urls
var dataArray=new Array();
dataArray[0]="images/img1.png";
dataArray[1]="images/img2.png";
dataArray[2]="images/img3.png";
dataArray[3]="images/img0.png";
//start with id=0 after 5 seconds
var thisId=0;
window.setInterval(function(){
$('#thisImg').attr('src',dataArray[thisId]);
thisId++; //increment data array id
if (thisId==3) thisId=0; //repeat from start
},5000);
});
</script>
Set this in head
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
jquery code
setInterval(function(){
$('#img').remove();
$('body').prepend('<img src="urlimgs" id="img">');
},5000);
I didn't understand what you want but it is so basic! You need learn more about jquery.. You can improve this code.. it is only a example
©2020 All rights reserved.