Todd Williams
Todd Williams

Reputation: 267

Javascript Condition - Not hiding ID

I'm trying to hide the ID "hide-homepage" and it's working overall, except for my second condition where I want to hide it at the stated URL (http://wgzrv.ndxva.servertrust.com/login.asp). Am I missing something?

<script type="text/javascript">    
    $(window).resize(function(){ 
        function showMyDiv() {
        if (window.location.href == "http://wgzrv.ndxva.servertrust.com") && (document.documentElement.clientWidth > 992) { 
        document.getElementById("hide-homepage").style.display="none";
        } else if (window.location.href == "http://wgzrv.ndxva.servertrust.com/login.asp") {
        document.getElementById("hide-homepage").style.display="none";
        } else if (document.documentElement.clientWidth < 992) {
        document.getElementById("hide-homepage").style.display="none";
        } else {
        document.getElementById("hide-homepage").style.display="block";
            }
        } 
    });
    </script>

Upvotes: 1

Views: 65

Answers (2)

Vadim
Vadim

Reputation: 179

Try instead of == using indexOf()

<script type="text/javascript">    
$(window).resize(function(){ 
    function showMyDiv() {
    if (window.location.href == "http://wgzrv.ndxva.servertrust.com") && (document.documentElement.clientWidth > 992) { 
    document.getElementById("hide-homepage").style.display="none";
    } else if (window.location.href.indexOf("http://wgzrv.ndxva.servertrust.com/login.asp") > -1) {
    document.getElementById("hide-homepage").style.display="none";
    } else if (document.documentElement.clientWidth < 992) {
    document.getElementById("hide-homepage").style.display="none";
    } else {
    document.getElementById("hide-homepage").style.display="block";
        }
    } 
});
</script>

EDIT (I removed the inner function, didn't see it the first time):

<script type="text/javascript">    
$(window).resize(function(){ 
    if (window.location.href == "http://wgzrv.ndxva.servertrust.com") && (document.documentElement.clientWidth > 992) { 
    document.getElementById("hide-homepage").style.display="none";
    } else if (window.location.href.indexOf("http://wgzrv.ndxva.servertrust.com/login.asp") > -1) {
    document.getElementById("hide-homepage").style.display="none";
    } else if (document.documentElement.clientWidth < 992) {
    document.getElementById("hide-homepage").style.display="none";
    } else {
    document.getElementById("hide-homepage").style.display="block";
        }
});
</script>

Upvotes: 1

void
void

Reputation: 36703

    if (window.location.href == "http://wgzrv.ndxva.servertrust.com") && (document.documentElement.clientWidth > 992) { 

should be

    if (window.location.href == "http://wgzrv.ndxva.servertrust.com" && document.documentElement.clientWidth > 992) { 

Upvotes: 1

Related Questions