views:

274

answers:

1

Hi all,

This should be an easy one, but I can't find a good example anywhere. I'm trying to select a particular element on my page that has a class of 'statuslight' and a title attribute of one of three options. The option (it will depend) is stored in a variable called 'currentStatus'. I've seen some examples, and I'm guessing this is the right track, but I need to know for sure:

$(".statuslight[title]='" + currentStatus + "'");

Thanks very much for the help.

+3  A: 

Very close:

$(".statuslight[title='" + currentStatus + "']");

Supposing your currentStatus is an array, you could get all statuslight elements with a title that contains any of the currentStatus values with:

$(".statuslight[title='" + currentStatus[0] + "'], .statuslight[title='" + currentStatus[1] + "'], .statuslight[title='" + currentStatus[2] + "']");

Alternatively, if your title has multiple statuses (title="status1 status2 status3"), and currentStatus is only one item you would use this selector:

$(".statuslight[title~='" + currentStatus + "']");
Joel Potter
Thanks Joel. `currentStatus` is not an array, just a simple string. I believe the top option should work. Thanks.
Mega Matt