View Single Post
Old 10-07-2012, 02:06 AM   PM User | #5
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
ok well you cannot start and id with a number. your image alreayd has an id of bg, you want to change the id of bg?

Code:
<script>
$(function() {
var images = ["chococat.gif","comic.gif","devil.gif","eye.gif"];
$('<img>').attr({'src':''+images[1],'id':'bg','title':''}).appendTo('#bg-wrapper').parent().fadeIn(1000);
    $('.change').click(function(e) {
    e.preventDefault();
    var ranImgNum = Math.floor(Math.random()*images.length)
    var image = images[ranImg];
        $('#bg').parent().fadeOut(800, function() {
            $('#bg').attr({'src':image, 'id':'ranimageid'+ranImgNum}); 
              $(this).fadeIn(800);
        });
    });
});
</script>
if you want to change the id of bg, this will do it
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote