Search code examples
javascripthtmltagsobsolete

Validation error, obsolete attribute


I'm currently working on a web page. Everything is working but when I went to validate, I ran into an error. The W3C validator says the name attribute is obsolete. Everything works, but no errors would be nice.

line from About_me.html

<img name="slide" alt="images about me" width="600" height="400">

line from slideshow.JS

function changeImg(){
    document.slide.src = images[i];

When I go to validate I get the following error "The name attribute on the img element is obsolete. Use the id attribute instead." When I change name to id the slide show no longer works. What to do?


Solution

  • If you change the field of the img element from name to id, then you will have to use

    document.getElementById("slide").src = images[i];
    

    instead of just

    document.slide.src = images[i];
    

    Hope this helps! :D