It is more involved than it could be because I added it to the previous instead of writing it as it’s own example.
Maybe some comments will help?
function maybe_strip_class(elem) {
// only bother with actual "tags"
if (elem.nodeType === 1) {
// determine if the tag has a class attribute
var class_attr = elem.hasAttribute("class");
// if so, it's truthy
if (class_attr) {
// get the attribute value as a strng
var elem_class_attr_val = elem.getAttribute("class");
// determine if the string has the text
if (elem_class_attr_val.indexOf("style_4") != -1) {
// if there are other values there will be a space, but otherwise not
// regex to deal with both to create a new value string
var class_attr_rem = (elem_class_attr_val).replace(/( )?(style_4)/, '');
// replace the value with the new one
elem.setAttribute('class', class_attr_rem);