Can I use floating point numbers inside div IDs?
I have a couple of divs on pages, some divs have IDs like word_float_number (example g开发者_StackOverflow社区roup_3.0 or group_4.0 , others just have word IDs). When I try to select these divs with jQuery, none of them are selected, like it cannot find them. Can I use number inside div IDs? I need to cluster elements by those floating point numbers on a page.
The problem is the . character. You need to escape (with \. in the JQuery selector) or remove it from the ids, because JQuery will intepret it as a css class devider.
I'm not sure you can use numbers in jQuery selectors, however as @nfechner says, you need to escape any . (dot) characters with a backslash due to it being a class selector and jQuery seeing it that way.
Using the Attribute Starts With Selector selector ([name^="value"]), you could select all word_[float] elements using this:
$('div[id^="word_"]')
Which will select any div with an id attribute starting with word_. You'd do the same with group_ like this:
$('div[id^="group_"]')
And so on.
加载中,请稍侯......
精彩评论