javascript - Getting error thrown in function with if + && condition -
this function:
window.addeventlistener("load", function() { var firstgal = document.queryselector(".containsnext"); var nextb = document.queryselector(".nondynamic"); var displayed = document.getelementsbyclassname('images')[0]; nextb.addeventlistener('click', function() { if (firstgal.style.opacity == 0 && displayed.style.backgroundimage == "url(http://i.dailymail.co.uk/i/pix/2014/03/07/article-2575552-1c1a7b9400000578- 567_964x673.jpg)") { firstgal.style.transform = "rotatey(360deg)"; firstgal.style.opacity = 1; firstgal.style.height = "200px"; firstgal.style.width = "500px"; firstgal.style.perspective = "400px"; forwardspain(); } else { firstgal.style.transform = "rotatey(0deg)"; firstgal.style.opacity = 0; firstgal.style.perspective = "400px"; forwardspain(); } }); }); what want test if opacity of firstgal 0 , if background of div ".images"(var = displayed/ dynamically created) has specific backgroundimage css value. run code. code runs fine without condition after "&&", cannot find issue.
when spain button clicked, .images div gets background image set, array. want check backgroundimage style on after spain button clicked. dev tools/console return this:
background-image: url(http://i.dailymail.co.uk/i/pix/2014/03/07/article-2575552-1c1a7b9400000578-567_964x673.jpg);
now error how assigned variable, maybe queryselector better find element, there on .images class. , not sure put "" after backgroundimage == . have tried "url(" + 'http://i.dailymail.co.uk/i/pix/2014/03/07/article-2575552-1c1a7b9400000578-567_964x673.jpg' + ")") well, error:
uncaught typeerror: cannot read property '0' of undefined pen.js:149 uncaught typeerror: cannot read property 'style' of undefined
looks var displayed undefined.
link full code, bit long, sorry that, it's above function doesnt work. line 65.
Comments
Post a Comment