• I was working on a loop in a page template that contained a few div ids. The page worked fine but when validated I got ID already defined errors.

    When I use div class I no longer get the errors. Is that because IDs can be used once in a page or is it a WordPress thing?

    just trying to figure it out..

Viewing 4 replies - 1 through 4 (of 4 total)
  • ID’s can be used once, classes can be used multiple times. You should use an id for, say, your header or footer. You should use a class for, say an H1.

    Yes, any repeated content should use classes.

    Thread Starter nemci7v

    (@nemci7v)

    Thank you for confirming! ?? I’ll keep that in mind.

    Tho.. I dont understand the advantage of ID divs.

    IDs are for elements that appear once on any given page, classes are for elements that may be displayed several times on a given page.

    Consider these 2 elements.

    <div id="red" class="title">A title</div>
    
    <div id="blue" class="title">A title</div>

    And some CSS ….

    .title {
    font-size:20px;
    padding:10px;
    }
    #red {
    color:red
    }
    #blue {
    color:blue
    }

    In such a case both elements inheirt the font-size and padding, but each use a different colour, determined by the ID…

    That’s one such example of why you’d use IDs.. (usually alongside classes)..

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘should I use div ID in a loop?’ is closed to new replies.