473,241 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

<img> width height

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

"Yes", I know the JavaScript will "not" manip anything, which is ok. I
simply do not know how to capture the width or height. Once I can do that I
can manipulate them.

Here is the HTML for the <img>
<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

--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW
Apr 21 '06 #1
10 3232
On Fri, 21 Apr 2006 21:46:37 GMT, News wrote:
I am trying to be able to manipulate the width and height of an <img> but do
not seem to be able.

"Yes", I know the JavaScript will "not" manip anything, which is ok. I
simply do not know how to capture the width or height. Once I can do that I
can manipulate them.

Here is the HTML for the <img>
<div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)">


There is a syntax error in this line, near the end. You're
missing an apostrophe. It should go:

<div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg');">

Don't know if that was what was breaking the code though.
Apr 21 '06 #2
ASM
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
Apr 22 '06 #3
test wrote:
On Fri, 21 Apr 2006 21:46:37 GMT, News wrote:
I am trying to be able to manipulate the width and height of an
<img> but do not seem to be able.

"Yes", I know the JavaScript will "not" manip anything, which is ok.
I simply do not know how to capture the width or height. Once I can
do that I can manipulate them.

Here is the HTML for the <img>
<div class="ImgMnp" id="myImg" onmouseover="imgSize('myImg','fpImg)">


There is a syntax error in this line, near the end. You're
missing an apostrophe. It should go:

<div class="ImgMnp" id="myImg"
onmouseover="imgSize('myImg','fpImg');">

Don't know if that was what was breaking the code though.


I did not know I need that apostrophe thanks.

Nope did not correct the problem, if I take out these two lines

var myWidth=myImage.style.width;
var myHeight=myHeight.style.height;

the function works, put them in the function crashes.
--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW
Apr 22 '06 #4
ASM wrote:
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.


What does this mean?? var myWidth= myImage.style&&myImage.style.width? myImage.style.width :
myImage.width; //attempt to capture width of <img>


At first I thought it was a triune if true this else that type statement but
I don't have a clue what it is.
--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW
Apr 22 '06 #5
ASM
News a écrit :

Nope did not correct the problem, if I take out these two lines

var myWidth=myImage.style.width;
var myHeight=myHeight.style.height;


Hu ?

myHeight=myHeight

from where comes this 2nd myHeight ?

would be better with the image 'myImag' , no ?

var myWidth=myImage.style.width; //attempt to capture width of <img>
var myHeight=myImage.style.height; //attempt to capture height of <img>
// ^^^^^^^
alert("myWidth+, +myHeight"); //show if I this function works
}
--
Stephane Moriaux et son [moins] vieux Mac
Apr 22 '06 #6
ASM
News a écrit :

What does this mean??
var myWidth= myImage.style&&myImage.style.width? myImage.style.width :
myImage.width; //attempt to capture width of <img>


At first I thought it was a triune if true this else that type statement but
I don't have a clue what it is.


yes it was (would have to be).

if myImage has style and myImage has style width,
miWidth is myImage.style.width
else
miWidth is myImage width

because perhaps your image has no style (or no width or height style) ?

in fact the error was much more stupid
(all as I've done in my code myWidth=myImage.style.height ! !)

--
Stephane Moriaux et son [moins] vieux Mac
Apr 22 '06 #7
ASM wrote:
News a écrit :

Nope did not correct the problem, if I take out these two lines

var myWidth=myImage.style.width;
var myHeight=myHeight.style.height;


Hu ?

myHeight=myHeight

from where comes this 2nd myHeight ?

would be better with the image 'myImag' , no ?

var myWidth=myImage.style.width; //attempt to capture width of <img>
var myHeight=myImage.style.height; //attempt to capture height of
<img> // ^^^^^^^
alert("myWidth+, +myHeight"); //show if I this function works
}


Greif I HATE it when I make stupid mistakes and simply cannot see them. Yup
it works and I have egg on my face.

Thanks and have a great weekend
--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW
Apr 22 '06 #8
ASM wrote:
News a écrit :

What does this mean??
var myWidth= myImage.style&&myImage.style.width?
myImage.style.width : myImage.width; //attempt to capture width of
<img>


At first I thought it was a triune if true this else that type
statement but I don't have a clue what it is.


yes it was (would have to be).

if myImage has style and myImage has style width,
miWidth is myImage.style.width
else
miWidth is myImage width

because perhaps your image has no style (or no width or height style)
?
in fact the error was much more stupid
(all as I've done in my code myWidth=myImage.style.height ! !)


I hope one day I will be able to avoid stupid mistakes or at the very least
find them before I air them to the WORLD ;-)

--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW
Apr 22 '06 #9
ASM
News a écrit :

I hope one day I will be able to avoid stupid mistakes or at the very least
find them before I air them to the WORLD ;-)


You may spend a long time runing around a stupid mistake
more they are stupid more it is difficult to find them

a new eye cand find them in seconds

ngs are there for that too.

--
Stephane Moriaux et son [moins] vieux Mac
Apr 22 '06 #10
VK

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


Listen, guys: "Micro$oft must die, and stuff"- but if you still want to
make your solution workable on the damned IE (which is not mandatory
but presuming if), it is not a shame at all to visit
<http://msdn.microsoft.com> and read what the producer has to say about
your question.

MSDN is going to put this sentence in bold soon I guess: "You want to
manipulate width/height - you *don't* hardcode it through the img
attributes, you use style rules instead". The rest of the attractive
reading is on MSDN :-)

Apr 22 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: MyndPhlyp | last post by:
I've been busting my head trying to figure this out for quite some time. With IE6 and NS7, no problems. I can simply code the HTML <img height="100%"> and be done with it. But NS4 and NS6 (and...
2
by: David D. | last post by:
If an <IMG> specifies a WIDTH but not a HEIGHT, then height is internally determined so as to maintain the image's aspect ratio. Aspect ratio is also preserved if HEIGHT but not WIDTH is...
9
by: Wladimir Borsov | last post by:
As well known for <IMG ...> tags in web pages a width and a height attribute can be applied. What I want to do now is to fix the width for ALL the images on my web page to exactly lets say 70 pixel...
5
by: homecurr | last post by:
I am writing a tool to generate html and have a problem with the <img> tag. The tool generates something like "<img src="...">". At the time the html is generated, the tool does not know the actual...
7
by: Zhang Weiwu | last post by:
Hello. This is problem puzzled me a long time. I wish to organize some block elements and let them flow one after each other like text. Think about a album, I wish the album have 12 thumbnails,...
15
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width:...
1
by: Carl | last post by:
Hi all I have a javascript function that drags and drops an element (ie img) into a container (ie bordered div). The function works and returns the element and and container. My next step is to...
4
by: bgold12 | last post by:
Hey, I've come across a strange behaviour that shows itself in IE 7.0 and Firefox 3 and probably other browsers. In the code below, which is a complete HTML document which validates as XHTML 1.0...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.