How do I change the ID of a HTML element with JavaScript?

前端 未结 3 1453
無奈伤痛
無奈伤痛 2020-11-28 08:15

I am modifying the ID of an HTML div element client side with JavaScript. The following code works OK in Internet Explorer but not in Firefox/2.0.0.20. It does

3条回答
  •  天涯浪人
    2020-11-28 08:30

    It does work in Firefox (including 2.0.0.20). See http://jsbin.com/akili (add /edit to the url to edit):

    One

    Link2

    The first click changes the id to "two", the second click errors because the element with id="one" now can't be found!

    Perhaps you have another element already with id="two" (FYI you can't have more than one element with the same id).

提交回复
热议问题