I have multiple classes throughout my page that are like:
<input class="someclass1 condition[operator]" type="text">
<input class="someclass2 condition[value]" type="text">
<input class="condition[percentage]" type="text">
I'd like to use jquery to basically loop through find("some_selector_i_need").each() but I'm not sure how to do this with wildcards.
Is this even possible? Something like find("condition[*]").each() where I could pull out what the * is as well?
I'd eventually like to format an array like:
Array
(
operator => 'value1',
value => 'value2',
percentage => 'value3'
)
var obj = {};
$('[class*="condition"]').each(function(i,ele) {
var type = ele.className.match(/\[(.*?)\]/)[1];
obj[type] = 'value' + (i+1);
});
FIDDLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With