2

Does anyone know how to select with jeury an id with this form 1329456738.1053,name?

Non working example: http://jsfiddle.net/zep6Y/

<div id="1329456738.1053,name">Some text</div>
<a href="#" class="publish_post" id="1329456738.1053">aaa</a>
$('#1329456738.1053,name').text()
Wesley Murch
  • 95,417
  • 36
  • 177
  • 220
Mike
  • 2,092
  • 1
  • 30
  • 44
  • 2
    I'm not sure that's a valid id.... – Xyan Ewing Mar 13 '12 at 21:45
  • @XyanEwing I believe, it is a valid ID in HTML5: http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html - although I would try my best to 'normalize' them in my own apps – Alex Pakka Mar 13 '12 at 21:49
  • The problem is that the dot is used as a class selector making it look for a css class named `1053`. The comma makes it look for a tag named `name`. – jgauffin Mar 13 '12 at 21:50
  • 1
    @XyanEwing AFAIK, the only disallowed characters in ID attributes are space characters ([HTML5 spec](http://www.w3.org/TR/html5/elements.html#the-id-attribute)). Though it's certainly not a very *sensible* ID... – lonesomeday Mar 13 '12 at 21:50
  • 1
    @lonesomeday: Thanks for that link! I haven't been keeping up with the changes in HTML5, now I guess `id="1♥♦♣♠☠"` is valid... – Wesley Murch Mar 13 '12 at 22:05

2 Answers2

6

Just checked, works:

$('.publish_post').click (function(){                        
                        alert (this.id);    
                        alert ($('#1329456738\\.1053\\,name').text());
})
Alex Pakka
  • 8,397
  • 3
  • 39
  • 65
0

This might be more consistent:

alert ($('[id="' + this.id + '"]').text());

Example

Joe
  • 73,764
  • 18
  • 123
  • 142