Re: <img> width height
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: <img> width height

From: ASM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid>
Date: Sat Apr 22 2006 - 01:48:20 CEST

News a écrit :
> I am trying to be able to manipulate the width and height of an <img> but do
> not seem to be able.

> <div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)">
> <img src="images/FirePlace.jpg" width="480" height="640" id="fpImg" />
> </div>
>
> Here is the JavaScript I tried to manipulate the <img>
> function imgSize(myID,myImg)
> {
> var myDiv= document.getElementById(myID); //get correct <div>
> var myImage=document.getElementById(myImg); //get correct <img>
> var myWidth=myImage.style.width; //attempt to capture width of <img>
> var myHeight=myHeight.style.height; //attempt to capture height of <img>
> alert("myWidth+, +myHeight"); //show if I this function works
> }
>
> Will someone please tell me what I am doing wrong

simplest way :

<img src="pict.jpg"
  onmousover="alert('width = '+this.width+' height = '+this.height)";>

maybe your code would be better with :

var myWidth= myImage.style&&myImage.style.width? myImage.style.width :
  myImage.width; //attempt to capture width of <img>
var myWidth= myImage.style&&myImage.style.height? myImage.style.height :
  myImage.height; //attempt to capture height of <img>

idea :
If your image didn't get a width or height style, you can't catch it.

-- 
Stephane Moriaux et son [moins] vieux Mac
Received on Mon May 1 05:14:13 2006