I spent years working as a .NET developer, and working with other programmers that used crazy abbreviations and all lower case for their variables, and it just made it really really hard to follow the progression of their code. So I started Camel Case then and just kept going with it since to me, it made it more readable.
For starters, you don’t need to check `#target` length, that’s an extra step that isn’t necessary. Checking `hasClass()` will return true or false and will execute only if true. Since we’re only checking for something specific, this is significantly more effective.
Second, setting a variable isn’t what we’re looking for, since you’ll be collecting *all* classes assigned to the `#target` div. What if you are looking for a classing of `red` but want to add a class of `blue` to the body?
Third, `$(document.body)` should be used over `$(‘body’)` based on speed alone.
You’re adding things that aren’t particularly necessary to this issue, my friend!
Hi, I’m new here but I saw TheDoc’s solution so I figured I should signup. I’m trying to add some colors to some CMS rendered code, and need a way to change a parent’s style, when an ID is present in the child. The problem is that new class is entered on all of the matching classes not just the one with the child.