views:

97

answers:

3

Im using the following:

url=location.href
fname=url.match(/.*\/(.*)\./)[1]
document.body.className=fname

This takes part of the URL and adds a class to the <body> tag with the text extracted from the URL.

However the problem with this method is the class only gets applied providing doesnt already have a class assigned.

Im really looking for something similar to the JQUERY .addClass function so body becomes:

<body class="originalClass filenameClass">

...

</body>
+2  A: 

document.body.className+=" "+fname

Y. Shoham
+3  A: 

You don't have to replace the class, just append to it like this:

document.body.className += " " + fname

You may want to run some validation though on everything that arrives via querystring...

Ariel
+1  A: 

With JQuery you can do $("body.className").addClass(fname) or similarly without JQuery you can do document.body.className += " " + fname

Aly