Irishgirl
Irishgirl

Reputation: 751

Simple JavaScript Swap function

I'm having difficulty in correcting the syntax error for image swap. I would appreciate if you can help me out as below?

function swap(i, s)
{
   var d = document.images;
   d ? d[i].src=s : null;
}

Upvotes: 0

Views: 70

Answers (1)

deadboy
deadboy

Reputation: 859

I think you want something like this

function swap(i, s) {
    var d = document.images;
    if (i >= 0 && i < d.length) {
        d[i].src = s;
    }
}

Upvotes: 1

Related Questions