Skip to main content
Inspiring
Oct 5, 2015 9:52 PM UTC
Answered

can same span id display more than 1x?

hi all,

is there a way to have the span id display more than 1x (the 1st shows up but not the next one) without extra javascript document.getElementById('name2***').textContent = "bob";?

html....

1 - the name is <span id="name"></span>


this doesn't show 2nd time

2 - again the name is <span id="name"></span>

<script>

document.getElementById('name').textContent = "bob";

</script>

    This topic is closed to new replies. Start a new post to keep the conversation going.
    Nancy OShea
    Nancy OSheaCorrect answer
    Community Expert
    Oct 5, 2015 9:55 PM UTC

    ID = a unique identifyer.  It doesn't matter what it is used on -- div, span, p etc...  It can be used only 1 x per page.  That's absolute & written in stone.

    Nancy O'Shea— Product User & Community Expert

    6 replies

    Jon Fritz
    Community Expert
    Community Expert
    Oct 5, 2015 9:59 PM UTC

    HTML ID's can only be used once per page.

    Not sure what you're attempting exactly, but maybe this would work better with a class...HTML DOM getElementsByClassName() Method

    Translate
    Nancy OShea
    Community Expert
    Community Expert
    Oct 5, 2015 10:04 PM UTC

    Of course that will invoke all of the same classes to fire at the same time; not separately.

    Nancy O.

    Translate
    Nancy O'Shea— Product User & Community Expert
    revdaveAuthor
    Inspiring
    Dec 24, 2015 5:33 PM UTC

    Thanks you Nancy & Jon - very helpful!

    Translate
    Nancy OShea
    Community Expert
    Nancy OSheaCommunity ExpertCorrect answer
    Community Expert
    Oct 5, 2015 9:55 PM UTC

    ID = a unique identifyer.  It doesn't matter what it is used on -- div, span, p etc...  It can be used only 1 x per page.  That's absolute & written in stone.

    Translate
    Nancy O'Shea— Product User & Community Expert
    revdaveAuthor
    Inspiring
    Oct 6, 2015 9:14 PM UTC

    Thanks Nancy - good to know

    Translate