jemand anders
Erfahrenes Mitglied
Hallo,
jemand eine Idee, wie ich Breite und Höhe der Fotos herausbekomme? Ich sehe nur null oder 0.
Gruß
jemand eine Idee, wie ich Breite und Höhe der Fotos herausbekomme? Ich sehe nur null oder 0.
Gruß
HTML:
<!DOCTYPE html>
<html lang="de">
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
</head>
<body>
<img id="bild1" src="https://www.tutorials.de/styles/tuts/xenforo/logo.png"><br/>
<img id="bild2"><br/>
<img id="bild3">
<script>
document.getElementById("bild2").src="https://www.tutorials.de/styles/tuts/xenforo/logo.png";
$("#bild3").attr("src", "https://www.tutorials.de/styles/tuts/xenforo/logo.png");
$("body").append("<p>Bild1:<br/>Javascript: width=" + bild1.style.width + "<br/>jQuery: $width=" + $("#bild1").width() + "<br/>Computed: " + window.getComputedStyle(document.getElementById("bild1")).getPropertyValue("width") + "<br/> document.images[0].width= " + document.images[0].width);
$("body").append("<p>Bild2:<br/>Javascript: width=" + bild2.style.width + "<br/>jQuery: $width=" + $("#bild2").width() + "<br/>Computed: " + window.getComputedStyle(document.getElementById("bild2")).getPropertyValue("width") + "<br/> document.images[1].width= " + document.images[1].width);
$("body").append("<p>Bild3:<br/>Javascript: width=" + bild3.style.width + "<br/>jQuery: $width=" + $("#bild3").width() + "<br/>Computed: " + window.getComputedStyle(document.getElementById("bild3")).getPropertyValue("width") + "<br/> document.images[2].width= " + document.images[2].width);
</script>
</body>
</html>
Zuletzt bearbeitet: