JS main approach:
<div id="x" class="widget-2 lang-ζ₯ζ¬θͺ">foo</div> function Element_getClassArgument(el, name) { var classes= el.className.split(' '); var prefix= name+'-'; for (var i= classes.length; i-->0;) if (classes[i].substring(0, prefix.length)==prefix) return classes[i].substring(prefix.length); return null; } Element_getClassArgument(document.getElementById('x'), 'widget');
If you want to include whitespace or a hyphen in the name, you will have to enter some kind of coding scheme, for example encodeURIComponent . But often you can leave without it.
A wrapper in something with $ in the name remains as an exercise for the reader. :-)
source share