I have a page that's created dynamically. It can have a number of different radio buttons with ID's like so:
In order to write change functions, I'm doing something like this:
$('[id^=cc-radio-opt-]').live("change", function() {
var idx = $(this).attr('id').split('-').pop();
});
This works well. But now, inside that change function, I need to hide a bunch of other related fields. They are named like this:
I need to be able to grab all the fields whose IDs begin with "cc" and end with the same number as the radio button that's been clicked (determined by the idx variable. I know I can get all the fields that start with "cc" by doing this:
$('[id^=cc-]');
But how can I also indicate that they need to end with whatever idx is? In other words, if the cc-radio-opt-1 radio is clicked, how can I get only cc-number-1 and cc-month-1?
解决方案
Well, you were almost there...
$('[id^=cc-][id$=1]')