vfclists
vfclists

Reputation: 20251

How can I use a regex to match a class or id in jQuery?

I am using the code below to expand a fieldset in Drupal based on the fieldset's id. The problem is that the id can only be used on a single content type, making it necesssary to duplicate it on all content types with a metatags field group.

Can the code be adjusted to match on any fieldsets that match an id prefixed by group_metatags_xxxxx

(function ($){
  Drupal.behaviors.dynamicCollapsedFieldset = {
    attach: function (context, settings) {
      $('.page-node-add #group_metatags').once('dynamic-collapsed-fieldset').removeClass('collapsed');
    }
  }
}(jQuery));

Upvotes: 0

Views: 81

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388436

What you are looking at is attribute starts with selector - it is a part of css attribute selectors

So try

$('.page-node-add [id^="group_metatags"]').once('dynamic-collapsed-fieldset').removeClass('collaps‌​ed');

Upvotes: 1

Related Questions