JSFiddle - React, Tailwind, and code Playground
by GMK Hussain
HTML
<div class="AddClassHere">
<h1>AddClassHere</h1>
<h2>Current URL is</h2>
</div>
CSS
b { color: #d06; }
JavaScript
var loc = $(location).attr('pathname');
var locClass = trimChar( loc ,'/');
$(".AddClassHere").addClass( locClass );
$( "h2" ).html( "Current URL is : ---> <b>" + locClass + "</b>");
//alert ( locClass );
function trimChar(string, charToRemove) {
while(string.charAt(0)==charToRemove) {
string = string.substring(1);
}
while(string.charAt(string.length-1)==charToRemove) {
string = string.substring(0,string.length-1);
}
return string;
}