topher-78
topher-78

Reputation: 3

jQuery images and the if/else statement

trying to hide/show div based on what images our visible. The "else" statement works but not the "if"

$(document).click(function() {  

    var t1 = document.getElementById("tpart1");     
    var t2 = document.getElementById("tpart2");     

    if (t1.src == 'images/team/bev_01.jpg' && t2.src == 'images/team/bev_02.jpg') {
        $("#bevbio").show("slow")    
    }

else {
        $("#annettebio").hide("slow")
        $("#bevbio").hide("slow")
        $("#keithbio").hide("slow")
        $("#krisbio").hide("slow")
        $("#mikebio").show("slow")
    }
});

Upvotes: 0

Views: 706

Answers (2)

Karthik Ganesan
Karthik Ganesan

Reputation: 4222

you can use something like this too

if (t1.src.indexOf('images/team/bev_01.jpg') > 0 && t2.src.indexOf('images/team/bev_02.jpg') > 0) {
        $("#bevbio").show("slow")    
    }

Upvotes: 0

David Thomas
David Thomas

Reputation: 253318

The src property will always be an absolute URL; you're testing the attribute, so you'd need:

t1.getAttribute('src')

Upvotes: 4

Related Questions