0

I want to use jquery to edit the class margin properties if its on homepage or admin, for instance , i am using class breadcrumb

.breadcrumb{margin-top:10px;margin-left:20px;}

What I want is to find the current url which is I think done by using:

 var pathname = window.location.pathname;

After getting the current path I need to check if its admin page or home page or common pages, so for common page , the margin-left should be 15px , while for home and admin page the margin-left should be 20px

Admin page url: www.mydomain.com/admin

home page url: www.mydomain.com

other pages url: www.mydomain.com/......

Can anyone help me how to achieve this , or is there any better way of doing this, Any help or assistance will be highly appreciated

5 Answers 5

2

Instead of using javascript/jQuery I would prefer to add a special class (e.g. <body class="admin"> and <body class="hp">) for admin pages and hp and I would write this css code

.breadcrumb {
    margin-top : 10px; 
    margin-left : 15px;
}

.hp .breadcrumb,
.admin .breadcrumb { margin-left: 20px; }
Sign up to request clarification or add additional context in comments.

Comments

1

if u want to do it using Jquery try like this

        $(document).ready(function() {
            var pathname = "window.location";

            var a=pathname.split('/');

 //checking for admin and home page

            if(a[1]=="admin"||a[1]==""){

                $("body").css("margin-left","20px");


            }

          else{
          $("body").css("margin-left","15px");

           }
        });

1 Comment

var pathname = window.location.path;
1

Try this: http://www.w3schools.com/jsref/jsref_indexof.asp

Comments

1

i would use .split('/') and then check if the pathname[1] == '', or 'admin', or other

Comments

1
if(pathname == admin || pathname == "")
{
 $("body").css("margin-left","20px");
}
else
{
 $("body").css("margin-left","15px");
}

write these on document.ready

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.