The omniscient user 'community' made an edit to this answer (How to add a class to body tag?), and I am baffled to the reasoning behind it.
The original answer was:
You can extract that part of the url using a simple RegExp:
var url = location.href;
var className = url.match(/\w+\/(\w+)_/)[1];
$('body').addClass(className);
However it was edited by community to:
You can extract that part of the url using a simple RegExp:
var url = location.href;
var className = url.match(/\w+\/(\w+)_/)[1];
var url = window.href;
$('body').addClass('className');
Two things I can see wrong with this answer:
- Community added an unneccesary line (
var url = window.href;
)
This is just redefining url
and is completely unnecessary.
- They added quotes around 'className'
className
is a variable, and therefore when using jQuery to add this as a class to the body, quotes should not be used else the class of body will be set to, literally, the string "className" when what was wanted was the result of url.match(/\w+\/(\w+)_/)[1];
Edit
It seems that this edit was made my an anonymous user, approved by three (!) out of four SO users and thus this unconstructive, and outright harmful edit, was approved. My second question is, what can we do about these kind of mindless and harmful edits (and users)?
See the post, the answer, and its revisions.