JavaScript Adding an ID attribute to another created Element

后端 未结 2 1637
Happy的楠姐
Happy的楠姐 2020-12-08 00:02

I have some code here that will do the following. The code creates an element \"p\" then I append it to a \"div\" in the HTML. I would like that \"p\" I just created have an

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 00:46

    Since id is an attribute don't create an id element, just do this:

    myPara.setAttribute("id", "id_you_like");
    

提交回复
热议问题