<img> width height

Discussion in 'Javascript' started by News, Apr 21, 2006.

  1. News

    News Guest

    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
    News, Apr 21, 2006
    #1
    1. Advertising

  2. News

    test Guest

    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.
    test, Apr 21, 2006
    #2
    1. Advertising

  3. News

    ASM Guest

    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
    ASM, Apr 22, 2006
    #3
  4. News

    News Guest

    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
    News, Apr 22, 2006
    #4
  5. News

    News Guest

    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
    News, Apr 22, 2006
    #5
  6. News

    ASM Guest

    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
    ASM, Apr 22, 2006
    #6
  7. News

    ASM Guest

    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
    ASM, Apr 22, 2006
    #7
  8. News

    News Guest

    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
    News, Apr 22, 2006
    #8
  9. News

    News Guest

    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
    News, Apr 22, 2006
    #9
  10. News

    ASM Guest

    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
    ASM, Apr 22, 2006
    #10
  11. News

    VK Guest

    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 :)
    VK, Apr 22, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RG90Y29t?=
    Replies:
    4
    Views:
    407
    =?Utf-8?B?RG90Y29t?=
    Nov 9, 2005
  2. Wladimir Borsov
    Replies:
    7
    Views:
    21,415
    eswar
    Apr 20, 2012
  3. Nonee
    Replies:
    7
    Views:
    658
    Nonee
    Oct 28, 2005
  4. MyndPhlyp

    Setting <img> height to match <td> height

    MyndPhlyp, Dec 21, 2003, in forum: Javascript
    Replies:
    5
    Views:
    189
    MyndPhlyp
    Dec 22, 2003
  5. Replies:
    7
    Views:
    177
    Tad McClellan
    Jun 22, 2006
Loading...

Share This Page