0

For example, I have a div element everywhere on the domain. and I want to delete it on ost page but not on the main page . for example I want to show it on www.spiele33.de but delete it on http://www.spiele33.de/uncategorized/moto-x3m-4-winter/ So, I want to do it with javascript

 <script>
    var currentUrl = window.location.href;

     if (currentUrl.indexOf('.de/') != currentUrl.length  - 4) // if it is not home page
     {
      var x = document.getElementsByClassName("entry-title h2-simulate-h1");
 x.style.display= "none";

     }
    </script>

but it does not work

2
  • 2
    This should be done on serverside. Commented Aug 8, 2018 at 11:27
  • 1
    If you do need to do this in script (and I agree you probably don't), see if you can generate something on the homepage that you can test, e.g. put a specific class on the body tag and check for that rather than trying to test the URL. Commented Aug 8, 2018 at 11:29

1 Answer 1

2

location.pathname contains everything after the domain, so check for location.pathname === '/'.

Sign up to request clarification or add additional context in comments.

1 Comment

To be more specific if (location.pathname === '/') { // hide element } should do the trick

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.