While filter
is an easy option, you could do a little preprocessed to select more quickly.
This code created an array of tickets, for easy access. This is good if they don't change often, and have small numbers (otherwise the array would be too big, but you can easily switch to an associative array):
var tickets = [];
$(function(){
$('div').each(function(){
var div = $(this);
var n = parseInt(div.text(), 10);
tickets[n] = div;
}); //div.each
tickets[12].css('color', 'red');
}); //doc.ready
The next option is less popular, but works well. jQuery does similar things internally, by the way. Here, we use attr
to add a custom attribute and select by it (if it bothers you, you can add a class like ticket12
, or use a standard attribute). This is easier to maintain than an array if you make a lot of changes to your page:
$(function(){
$('div').each(function(){
var div = $(this);
var n = div.text();
div.attr('ticket', n);
}); //div.each
$('[ticket=3]').css('color', 'blue');
}); //doc.ready
See both examples in action here: http://jsbin.com/etapu3