regex - jQuery - regexp selecting and removeClass()? -
i've been given several auto-generated html docs thousands of lines long, , need clean source. need remove classnames "table-col-##". two-step problem:
- select , classes have table-col-##, ## integer between 0-999
- remove matching class element, without removing of other classes
so boils down to: need way, if possible, use regexps in $() selectors, , either obtain selected class in each() - or apply regexp $.removeclass(). can point me in right direction?
update: there sort of $.removeclass([selected]) functionality? seems easiest way solve second part.
if numbers acceptable, there can other characters too, start (not tested, edited comments):
$("[class^='table-col-']").removeclass( function() { /* matches table-col-row */ var toreturn = '', classes = this.classname.split(' '); for(var = 0; < classes.length; i++ ) { if( /table-col-\d{1,3}/.test( classes[i] ) ) { /* filters */ toreturn += classes[i] +' '; } } return toreturn ; /* returns classes removed */ });
Comments
Post a Comment