I know with JavaScript (jQuery, anyway), you can specify an element based on what its ID begins with, what it ends with, or the whole shebang, but what about a combination of what it begins with and ends with?
I have brute-forish code like this:
if (nextD8 == 2) {
// There mus be a way to perform removeClass() on all ids that begin with "td" and end with "N", right?
$("#tdDate2").removeClass("hide");
$("#tdAirfare2").removeClass("hide");
. . .
$("#tdgrandtotaldate2").removeClass("hide");
}
...which I'd like to reduce to something like:
if (nextD8 == 2) {
$("#td~2").removeClass("hide");
}
...where the tilde means "whatever/anything". Is this possible?
I don't need/want a CSS solution, but a Javascript one, as I need to remove a class via Javascript.
UPDATE
The solution, inspired by showdev, allows the previous long-winded code to be replaced by:
if (nextD8 == 2) {
$('td[id^="td"][id$="2"]').removeClass("hide");
}
. . .
UPDATE 2
I minified the logic down to this:
var selstr = 'td[id^="td"][id$="' + nextD8 + '"]';
$(selstr).removeClass("hide");
if (nextD8 == 6) {
$("#addDate").hide();
}
...which is enough to allow the user to continue "adding" (unhiding) columns 2..6, and thereafter hiding the "Add New Date" button.