I want to add a class to a body tag with jQuery.
For example if the URL is http://www.mywebsite.com/about_us.asp, I want add the first five letters, in this case ‘about’, to the body tag:
<body class="about">
How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This should do it:
The whole “five characters” thing is a little worrisome; that kind of arbitrary cutoff is usually a red flag. I’d recommend catching everything until an _ or .:
That pattern should yield the following:
../about_us.html: about../something.html: something./has_two_underscores.html: has