Jump to content

 

pablo631

Member Since 07 Dec 2011
Offline Last Active Jun 21 2013 02:48 PM
-----

Posts I've Made

In Topic: Add Dynamic Body Class or ID?

19 April 2013 - 04:27 PM

Thanks. That doesn't actually add the name of the specific page or even the ID.

This is what I get on a page now.

<body id="pages" class="view page">


But it does work on categories pages now :) So if I use both I can now target pretty much any page I want now with CSS.

Thanks for your help.

In Topic: Add Dynamic Body Class or ID?

18 April 2013 - 09:13 PM

I guess I'll answer my own question.

This isn't exactly what I wanted but it's enough to do the trick for now. This will add a class to the html element based on the first word of the page name. So if your page is called "about-our-company.html" It will add "about" as a class to the html element.

Add this to your head.

{literal}
<script type="text/javascript">
    var loc = window.location.pathname.match(/^\/?(\w+)\b/);
    // document.documentElement is the html element, this adds the class
    if(loc) document.documentElement.className += " " + loc[1].toLowerCase();
</script>
{/literal}