Code : Tout sélectionner
function clearCoor() {
document.getElementById("myImgaa").src = "";
}Code : Tout sélectionner
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onmousemove Event</h2>
<input class="form-control" type="text" name="ville" value="" id="ville" placeholder="" required="required" />
<div style ="width: 200px;
height: 100px;
border: 1px solid black;"onmousemove="myFunction(event)" onmouseout="clearCoor()"></div>
<img id="myImgaa" src="" width="107" height="98">
<script>
function myFunction() {
//alert(document.getElementsByName("ville"));
if (document.getElementsByName('ville') !== null && document.getElementsByName('ville') !== '')
{ document.getElementById("myImgaa").src = "https://www.w3schools.com/jsref/img_pulpit.jpg";}
else
{ document.getElementById("myImgaa").src = "";}
}
function clearCoor() {
}
</script>
</body>
</html>Code : Tout sélectionner
<html>
<body>
<h1>HTML DOM Events</h1>
<h2>The onmousemove Event</h2>
<input class="form-control" type="text" name="ville" value="" id="ville" placeholder="" required="required" />
<div style ="width: 200px;
height: 100px;
border: 1px solid black;"onmousemove="myFunction(event)" onmouseout="clearCoor()"></div>
<img id="myImgaa" src="" width="107" height="98">
<script>
function myFunction() {
const ville = document.querySelector('[name="ville"]');
if (ville !== null && ville.value !== '')
{
document.getElementById("myImgaa").src = "https://www.w3schools.com/jsref/img_pulpit.jpg";
} else {
document.getElementById("myImgaa").src = "";
}
}
</script>
</body>
</html>