Results 1 to 2 of 2

Thread: changing and image in another cell/location

  1. #1
    Join Date
    Aug 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default changing and image in another cell/location

    Hello,

    I have a web page with 24 slices/cells, I need to change a picture in another cell when you mouse over a picture in the current cell.

    In other words I have a picture in cell 14 and I need to change the picture in cell 23 when you mouse over the picture in cell 14.

    how is this done?

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    Hope this basic example keeps you going:
    HTML Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title></title>
    <style type="text/css">
    *{margin:0px;padding:0px;}
    #wrap{width:700px;margin:20px auto;}
    table{background:#555;}
    img{width:200px;height:150px;}
    td{background:#fff;width:200px;text-align:center;height:100px;}
    </style>
    <script type="text/javascript">
    window.onload=function(){
    for(var i=0,img=document.getElementById('wrap').getElementsByTagName('img');i<img.length;i++)
    	{
    	if(img[i].getAttribute('id')){
    		img[i].onmouseover=function(){
    		document.getElementById(this.getAttribute('rel')).src=this.src;}
    		img[i].onmouseout=function(){
    		document.getElementById(this.getAttribute('rel')).src='http://h1.ripway.com/rangana/images/'+this.className+'.jpg';}
    		}
    	}
    }
    </script>
    </head>
    <body>
    <div id="wrap">
    <table cellspacing="1px">
    <tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td></tr>
    <tr><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td><td>12</td></tr>
    <tr><td>13</td><td><img src="http://h1.ripway.com/rangana/images/Picture4.jpg" alt="mypic" id="i14" rel="i23" class="Picture7">14</td><td>15</td><td>16</td><td>17</td><td>18</td></tr>
    <tr><td>19</td><td>20</td><td>21</td><td>22</td><td><img src="http://h1.ripway.com/rangana/images/Picture7.jpg" alt="myheart" id="i23" rel="i14" class="Picture4">23</td><td>24</td></tr>
    </table>
    </div>
    </body>
    </div>
    Important attributes are:
    • id - give your image element a unique identifier
    • rel - the rel attribute will be your target id (the id of the image you want to change).
    • class - this should be the same as to your original image's source name (without extension).
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •