Q:

Jquery getElementById - multiple instances within one script tag?

My current script identifies an element in my HTML with this line
document.getElementById("one" ).src = images[random_no];

Is there a way to use one instance of  on multiple ids - in my case image tags. This current script affects only one image with its effect. I want to use that one script to affect multiple images in my code.
document.getElementById("one, two, three" ).src = images[random_no];

I know that doesn't work :) just trying to further illustrate :)

A:

in Jquery 
$("#one,#two,#three").attr('src',images[random_no]);

try using this code
Working Demo http://jsfiddle.net/cse_tushar/MYua5/1/
i=0;
$("#one, #two, #three" ).attr("src", function() {
    i++;
    return i+'.jpg';
});

Random generation of images 
Working demo http://jsfiddle.net/cse_tushar/MYua5/3/
function randomFromInterval(from, to) {
    return Math.floor(Math.random() * (to - from + 1) + from);
}
var images = new Array('1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg');
var len = images.length;
$("#one, #two, #three").each(function () {
    x = randomFromInterval(0, len-1);
    var img_no = (x >= 0 && x < len) ? x : randomFromInterval(0, len-1);
    $(this).attr('src', images[img_no]);
});

new code 
working Demo http://jsfiddle.net/cse_tushar/MYua5/4/
var images = new Array('1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg');
var len = images.length;
i = 0;

function getImages() {
    $("#one, #two, #three").each(function () {
        $(this).attr('src', images[i]).attr('alt', images[i]);
        if (i == len-1) {
            i = 0;
        } else {
            i++;
        }
        console.log(i);
    });
}
getImages();
setInterval(getImages, 1000);

A:

The other answers here show you how to set all three to the same image.
If you want them each to get different images, then:
$("#one, #two, #three" ).attr("src", function() {
    /* ...generate new random_no here... */
    return images[random_no];
});

If you pass a function into attr as the second argument, it gets called for each element in the set, and the return value is used for the attribute value.

