Search code examples
javascriptjquerysizzle

Complex Selector breaks in jQuery 1.8, but worked in 1.7.2


I have some HTML like this (yep, it's a bit weird, but it's an existing project):

<table>
<tr id="21.30---22.00">
    <td class='51'>Text</td>
</tr>
</table>​

And some JS like this:

$(document).ready(function(){
    var time = "21.30---22.00";

    // jQuery needs . to be escaped to \\.
    // Regex needs \ to be escaped as \\. 
    // JS needs \ to be escaped as \\.

    time = time.replace(/\./g,'\\\\\\.');

    $("tr#" + time + " td.51").css("color","blue");
});​

In reality, the time string is produced from some JSON, hence the weird way round.

This worked in previous versions of jQuery, but doesn't in 1.8, presumedly due to the changes in Sizzle. Here is an example of it not working:

jQuery 1.7.2: http://jsfiddle.net/VnA4m/

jQuery 1.8: http://jsfiddle.net/VnA4m/1/

Any ideas of how I can get from my time = "21.30---22.00" to a selector that works in 1.8?


Solution

  • try this code--- it will select by using attribute selector

    $("[id='21.30---22.00']").foo