In this article I will describe how to hide and show html content with any ID based on an expression in the site URL.
This code is built in javascript so we expect it to work on almost all systems. Descriptions of this code are given below.

You can hide an item with the following code.

<script>
//In the URL containing HOME.COM/CATEGORY1/SUBCATEGORY1, the item with the ID HIDE-CONTENT will be hidden.
if (window.location.href.indexOf("/CATEGORY1/SUBCATEGORY1") != -1)
{ document.getElementById('HIDE-CONTENT').style.display = 'none'; };
>
</script>

You can show any element on pages with specified URL layout with below code. It will be hidden everywhere else. Before doing this, make sure you add the style style=”display:none” to the element. Thus, content that is already hidden will only be visible on certain pages.
<script>
//In the URL containing HOME.COM/CATEGORY/SUBCATEGORY the item with the id SHOW-CONTENT will be displayed.
//Assuming you saved this item as hidden before.
if (window.location.href.indexOf("HOME.COM/CATEGORY/SUBCATEGORY") != -1)
{ document.getElementById('SHOW-CONTENT').style.display = 'inline-block'; };
</script>

 

 

Leave a Reply