Results 1 to 5 of 5

Thread: IF statment around styles

  1. #1
    Join Date
    May 2009

    IF statment around styles

    I was wondering if it is possible to do this? Page is in HTML, uses javascript

    I have left navgation which uses a style <div id="left"> On certain pages I want to use another style so I have created a new class <div id="leftmenu">

    so what I want to do is:

    if page = a
    display leftmenu class
    left class

    Can someone help me with the code so that it will work?

  2. #2
    Join Date
    Nov 2002
    IIRC, you could use an id in the <body> tag and then change the value based on the page, ie <body id="index">. This way you can set up your CSS like this

    #index .left {
    CSS code
    This should let you code for a class named left within an id named index.

  3. #3
    Join Date
    May 2009
    That wont work, it is a bit of a strange cms system I am using. I only have access to the leftnav code and the cms and cant access the body area which is why I am trying to come up with an if statement

  4. #4
    Join Date
    Dec 2005
    Oops, didn't read the fact that you can't access the body code (although people who say that always make me sceptical).

    What language is your CMS in?
    I've switched careers...
    I'm NO LONGER a scientist,
    but now a web developer...

  5. #5
    Join Date
    Nov 2007
    Use the above suggestion (use an ID on the body tag)
    with some JS to get you the current page's name and you can update the body tag on the fly.

    <script type="text/javascript">
    	var sPath = window.location.pathname;
    	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    	if ( sPage == 'A.html' ) {
    Preferably, this code would go in an onload function, but it seems to work just fine stand-alone at the bottom of the page.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles