Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
533 views
in Technique[技术] by (71.8m points)

html - How to select an element that has an ID which begins with a digit?

<div id="634670717473476800" align="center" style="width: 100%; overflow-y: hidden;" class="wcustomhtml">

I have the above HTML (autogenerated, cannot change) and I try to select the entire DIV in CSS. There are several "wcustomhtml" on the page so the ID is my only choice. Straightforward I would think.

But I am not able to select it, and I don't understand why.

Neither #634670717473476800 nor div#634670717473476800 manages to select the div. Can one not select an ID consisting of numbers only?

So if it is valid HTML, what can be wrong? Neither Chrome's inspect element nor Firebug lets me create rules based on the ID in the inspector.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can access it by using an attribute selector and selecting the ID attribute:

[id='634670717473476800'] {
  background-color: red;
}
<div id="634670717473476800" align="center" style="width: 100%; overflow-y: hidden;" class="wcustomhtml">div</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...