1

I'm a complete noob when it comes to javascript. Would there be anyway to change an image after it is clicked, some way to trigger a js function to change the css. It would have to be triggered by an event and something other than onclick, onfocus probably.

<style>
    #pic {
    width:100px;
    height:100px;
    }
</style>
</head>
<body>

<img src='nope.jpg' id='pic' onclick="mouseOver()"></img>

<script type='text/javascript'>
    function mouseOver() {
    document.getElementById('pic').style.width="400px";
    document.getElementById('pic').style.height="400px";
    }       
</script>
user3487092
  • 11
  • 1
  • 1
  • 3

5 Answers5

1

try this...

function mouseOver() {
   document.getElementById('image').style.height = "400px";
}
kyros
  • 153
  • 1
  • 2
  • 11
0

First i edited the question , because the function was not defined correctly .

Second :

to access the height property of any element , you should use style.height , and should add "px" to the value.

please spend more time searching for answers , instead of posting a new question.

ProllyGeek
  • 15,517
  • 9
  • 53
  • 72
0

Change the JS to this:

var image =  document.getElementById('image');

function mouseOver() {
    image.style.height="600px";
}

image.onclick = mouseOver;
javakorr
  • 76
  • 3
0

Setting values you can use directly style attribute, but remember that asking for them is a greater problem:

Please refer to this one: Get a CSS value with JavaScript

Community
  • 1
  • 1
Phaedra
  • 237
  • 1
  • 3
  • 11
0

This should work

<style>
#pic {
width:100px;
height:100px;
}
</style>
</head>
<body>   
<img
       width="100"
       onmouseOver="this.width=400; this.height=400"
       onclick="this.width=100"
       alt="RESIZE IMAGE"
       id='pic'
       src='nope.jpg'
    />

just copy and edit the image tag code as needed

DcHerrera
  • 80
  • 1
  • 11