change image use javascript DOM

Posted by user289346 on Stack Overflow See other posts from Stack Overflow or by user289346
Published on 2010-03-18T06:01:03Z Indexed on 2010/03/18 6:11 UTC
Read the original article Hit count: 397

Filed under:
|
|
|
<html>
<head>
<script type="text/javascript">
var curimage = "cottage_small.jpg";   
var curtext = "View large image"; 
function changeSrc() { 
    if (curtext == "View large image"||curimage == "cottage_small.jpg") { 
        document.getElementById("boldStuff").innerHTML = "View small image"; 
        curtext="View small image"; 
        document.getElementById("myImage")= "cottage_large.jpg"; 
        curimage = "cottage_large.jpg";
    } else { 
        document.getElementById("boldStuff").innerHTML = "View large image"; 
        curtext = "View large image"; 
        document.getElementById("myImage")= "cottage_small.jpg"; 
        curimage = "cottage_small.jpg"; 
    } 
} 
</script> 
</head>
<body> 
    <!-- Your page here --> 
    <h1> Pink Knoll Properties</h1>
    <h2> Single Family Homes</h2> 
    <p>
        Cottage:<strong>$149,000</strong><br/>
        2 bed, 1 bath, 1,189 square feet, 1.11 acres <br/><br/> 
        <a href="#" onclick="changeSrc()"><b id="boldStuff" />View large image</a>
    </p>  
    <p><img id="myImage" src="cottage_small.jpg" alt="Photo of a cottage"  /></p> 
</body>
</html>

This is my coding I need to change the image and text the same time when I click it.

I use LTS, it shows the line document.getElementById("myImage")= "cottage_large.jpg";

is a wrong number of arquments or invalid property assigment.

Dose someone can help?

Bianca

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about function