Regular expression in data attribute - jquery

I have current html:

<input id="dynamic1" /* other */ data-group-animal="y1,y2" /> <input id="dynamic2" /* other */ data-group-vegetable="y3,y4" /> 

These are independent divs that can be shared or not when sending data via ajax.

Now I have one use case for both fields, and I need to get data-value for both options based on some parameters. the data attribute is different (used for different purposes - I can send either not all groups or separately)

so i want:

$('input').data('group*') but this does not work, then I understand that I need a regular expression.

Does regexp exist for a data attribute that I can use?

+7
source share
1 answer

If you change your attributes, you can use selectors.

http://jsfiddle.net/kvJVM/1/

So, instead, you can use data-group-type and a query for this:

 <input id="dynamic1" data-group-type="animal" data-group="y1,y2" /> <input id="dynamic2" data-group-type="vegetable" data-group="y3,y4" />​ 

Some sample queries

 $('input[data-group]') // all $('input[data-group-type^="animal"]') // starts with 'animal' $('input[data-group-type*="l"]') // contains 'l' $('input[data-group-type!="animal"]') // not 'animal' 

There are other selectors: http://api.jquery.com/category/selectors/

+22
source

All Articles