Skip to main content
Inspiring
October 5, 2015
Answered

can same span id display more than 1x?

  • October 5, 2015
  • 2 replies
  • 863 views

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 has been closed for replies.
    Correct answer Nancy OShea

    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.

    2 replies

    Jon Fritz
    Community Expert
    Community Expert
    October 5, 2015

    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

    Nancy OShea
    Community Expert
    Community Expert
    October 5, 2015

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

    Nancy O.

    Nancy O'Shea— Product User & Community Expert
    revdaveAuthor
    Inspiring
    December 24, 2015

    Thanks you Nancy & Jon - very helpful!

    Nancy OShea
    Community Expert
    Nancy OSheaCommunity ExpertCorrect answer
    Community Expert
    October 5, 2015

    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
    revdaveAuthor
    Inspiring
    October 6, 2015

    Thanks Nancy - good to know