0

how can i use a Regex to select all checkboxes that have ids like

edit-field-media-en-cat-value-1080-children-1122-children-1249-checkbox

edit-field-media-en-cat-value-1080-children-1125-children-1259-checkbox

and

edit-field-media-en-cat-value-1080-children-1249-checkbox

edit-field-media-en-cat-value-1080-children-1122-checkbox

Where the IDS (numbers in the middle) change.

3 Answers 3

1

Why not use the attribute selector and "starts with" :

$('input[id^="edit-field-media"][id$="children-1249-checkbox"]')

You can even use both the starts with and ends with selector together ?

Sign up to request clarification or add additional context in comments.

1 Comment

The IDS change , the 1080 change from element to another
0

You can do it with ends with selector:

$(":checkbox[id$='1249-checkbox'], 
   :checkbox[id$='1259-checkbox'], 
   :checkbox[id$='1122-checkbox']");

This way you will get the checkboxes with those specific identifiers (1249,1259,1122) so in case there are similar checkboxes but with different identifiers they will not get into your selection.

So I'm assuming you want the checkboxes of those specific items among a group of similar items.

2 Comments

ok , how can i get those who have value-ANY-children-ANY-children-ANY-checkbox where ANY is a number ?
I've posted a new answer for that, it's using a custom jquery selector to solve it.
0

To get checkboxes with the pattern value-ANY-children-ANY-children-ANY-checkbox you can use a custom selector, like this:

$.expr[':'].mychecks = function(elem, i, match, stack) {
   reg = /value-[0-9]+-children-[0-9]+-children-[0-9]+-checkbox/g
   return reg.test(elem.id);
};

then use it like:

$(':checkbox:mychecks');
//or the equivalent
$('input[type=checkbox]:mychecks');

See working demo .

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.