0

How to, in one selector, account for a selector that has a format like attr1, attr2, attr3 etc until attr9 so that I can create a click method in jQuery? I'm unable to come up with anything myself I'm sure and I'm tired here at work and can't think straight!!

Any ideas? Thanks! Here's what I have

$( () => {
    $('#attr' + ).click( () => {
        $(this).next('div').slideToggle();

        $(this).parent().siblings().children().next().slideUp();
        return false;
    });
});
rec0nstr
  • 185
  • 8
  • I think a regex would be the way to go. https://stackoverflow.com/questions/190253/jquery-selector-regular-expressions – Félix Paradis Feb 12 '20 at 22:09
  • 2
    You need `$('[id^=attr]')` (although this will match any id that starts with `attr`. why are you working with sequential IDs in the first place? Can't you use something like `#parent > div` instead?) –  Feb 12 '20 at 22:19
  • 1
    Use a class instead. Super easy. – Taplar Feb 12 '20 at 22:56

0 Answers0