Swap image without name tag.

Discussion in 'Javascript' started by Joachim, Apr 27, 2006.

  1. Joachim

    Joachim Guest

    Hi.

    I have a function that swap images. But in the image element i use the tag
    "name" to give name that i send to my java script function:

    <img src="greensmiley.jpg" name="smiley" alt="gubbe" onmouseover="swapImage('smiley',
    'CoolSmiley.jpg')" onmouseout="swapImage('smiley','greensmiley.jpg')" />

    But to have a valid xhtml1.1 document you cant use the "name" tag. I've tried
    with the id tag but then my function dont work. Is there any other tag to
    use? Or how do you solve this?

    Best regards Joachim
     
    Joachim, Apr 27, 2006
    #1
    1. Advertising

  2. Joachim wrote:
    > I have a function that swap images. But in the image element
    > i use the tag "name"


    It is an attribute not a tag.

    > to give name that i send to my java script function:
    >
    > <img src="greensmiley.jpg" name="smiley" alt="gubbe"
    > onmouseover="swapImage('smiley', 'CoolSmiley.jpg')"
    > onmouseout="swapImage('smiley','greensmiley.jpg')" />
    >
    > But to have a valid xhtml1.1 document you cant use the
    > "name" tag. I've tried with the id tag but then my
    > function dont work.

    <snip>

    Then you change the function so that it does work. In an XHTML DOM it
    should be possible to reference an IDed IMG element through the -
    document.images - collection, or use document.getElementById to retrieve
    a reference to it.

    Richard.
     
    Richard Cornford, Apr 27, 2006
    #2
    1. Advertising

  3. Joachim

    marss Guest

    Joachim напиÑав:
    > Hi.
    >
    > I have a function that swap images. But in the image element i use the tag
    > "name" to give name that i send to my java script function:
    >
    > <img src="greensmiley.jpg" name="smiley" alt="gubbe" onmouseover="swapImage('smiley',
    > 'CoolSmiley.jpg')" onmouseout="swapImage('smiley','greensmiley.jpg')" />
    >
    > But to have a valid xhtml1.1 document you cant use the "name" tag. I've tried
    > with the id tag but then my function dont work. Is there any other tag to
    > use? Or how do you solve this?



    You can use "this" keyword in the event handler. "this" is the object
    captured event.

    html:
    <img onmouseover="swapImage(this, 'CoolSmiley.jpg')"
    onmouseout="swapImage(this,'greensmiley.jpg')" ....

    javascript:
    function swapImage(sender, imgSrc){
    sender.src = imgSrc;
    }

    Or, more simpler:
    <img onmouseover="this.src='CoolSmiley.jpg';"
    onmouseout="this.src='greensmiley.jpg';" ....
     
    marss, Apr 28, 2006
    #3
  4. Joachim wrote:

    > I have a function that swap images. But in the image element i use the tag
    > "name" to give name that i send to my java script function:


    "java script"?

    > <img src="greensmiley.jpg" name="smiley" alt="gubbe"
    > onmouseover="swapImage('smiley', 'CoolSmiley.jpg')"
    > onmouseout="swapImage('smiley','greensmiley.jpg')" />


    <URL:http://pointedears.de/hoverMe/>

    > But to have a valid xhtml1.1 document you cant use the "name" tag.


    Certainly you don't need or want XHTML 1.1 these times. And most certainly
    you do not even need or want XHTML these times. Search the archives.


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
     
    Thomas 'PointedEars' Lahn, Apr 28, 2006
    #4
  5. Joachim

    Randy Webb Guest

    Thomas 'PointedEars' Lahn said the following on 4/28/2006 9:12 AM:
    > Joachim wrote:
    >
    >> I have a function that swap images. But in the image element i use the tag
    >> "name" to give name that i send to my java script function:

    >
    > "java script"?


    Yes, moron, that is what he said. Your overly pedantic idiotic behavior
    is displaying itself again.

    >> <img src="greensmiley.jpg" name="smiley" alt="gubbe"
    >> onmouseover="swapImage('smiley', 'CoolSmiley.jpg')"
    >> onmouseout="swapImage('smiley','greensmiley.jpg')" />

    >
    > <URL:http://pointedears.de/hoverMe/>


    And then don't.

    >> But to have a valid xhtml1.1 document you cant use the "name" tag.

    >
    > Certainly you don't need or want XHTML 1.1 these times. And most certainly
    > you do not even need or want XHTML these times. Search the archives.


    Finally, something that makes sense came from you.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Apr 29, 2006
    #5
    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. shruds
    Replies:
    1
    Views:
    871
    John C. Bollinger
    Jan 27, 2006
  2. Phillip Roncoroni
    Replies:
    6
    Views:
    6,212
  3. Steve
    Replies:
    50
    Views:
    26,712
  4. Niels Dekker (no reply address)

    What swap is called when using std::swap?

    Niels Dekker (no reply address), Jul 19, 2006, in forum: C++
    Replies:
    4
    Views:
    999
    Niels Dekker (no reply address)
    Jul 20, 2006
  5. Clay
    Replies:
    1
    Views:
    158
    Elegie
    Sep 28, 2006
Loading...

Share This Page