javascript - Issue with getting focus -
i'm trying change img if user clicks anywhere inside specified div element. nothing happening, know must wrong.
so far have this
setinterval("myfunction()", 1); function myfunction() { if document.getelementbyid("demo").hasfocus; { document.getelementbyid('pic1').src='https://pbs.twimg.com/profile_images/701853789855346689/ikxiygko.png'; } else { document.getelementbyid('pic1').src='https://pbs.twimg.com/profile_images/688766010837446657/2dgfpaq6.png'; } } <div style="border-style: solid;height:20px;" id="demo"></div> <img id="pic1" src="https://pbs.twimg.com/profile_images/688766010837446657/2dgfpaq6.png">
not sure if i'm getting right you're trying do. can see working code here :
you had typos in code , missed parenthesis if condition
var demo = document.getelementbyid('demo'); demo.addeventlistener('click', myfunction, false); function myfunction() { if (document.getelementbyid("demo") === document.activeelement) { document.getelementbyid('pic1').src = 'https://pbs.twimg.com/profile_images/701853789855346689/ikxiygko.png'; } else { document.getelementbyid('pic1').src = 'https://screenshots.fr.sftcdn.net/fr/scrn/76000/76818/microsoft-small-basic-22.jpg'; } } <div style="border-style: solid;height:20px;" id="demo"></div> <img id="pic1" src="https://pbs.twimg.com/profile_images/688766010837446657/2dgfpaq6.png">
Comments
Post a Comment