I want to parse data-action in the string below. I’ve managed to get the data inside it, but I want to parse it so that “action” = togglestate and “params” = anything inside the brackets. I ‘m not too good at regex but I’m currently using this with no avail: (This code is in the execaction function)
var regex = /(.*)(\((.*)\))?/gi;
var list = elem.dataset.action.match(regex);
var action = list[1];
var params = list.splice(0,2).join();
HTML:
<div data-action='toggleState(test)' onClick='execaction(this);' id='testelem'>div running execaction on click with action parameter</div>
1 Answer