Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to modify this code to also give this div item an ID, however I have not found anything on google, and idName does not work.(我正在尝试修改此代码,以便为此div项目提供ID,但是我在google上找不到任何内容,并且idName不起作用。)

I read something about append , however it seems pretty complicated for a task that seems pretty simple, so is there an alternative?(我读了一些关于追加的内容 ,但对于看似非常简单的任务而言似乎相当复杂,那么还有其他选择吗?) Thanks :)(谢谢 :)) g=document.createElement('div'); g.className='tclose'; g.v=0;   ask by pufAmuf translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
125 views
Welcome To Ask or Share your Answers For Others

1 Answer

You should use the .setAttribute() method:(您应该使用.setAttribute()方法:)

g = document.createElement('div'); g.setAttribute("id", "Div1");

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...