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>
2
  • based on your example no JS is required. look into css3 transitions on hover Commented Apr 1, 2014 at 22:32
  • It would have to be js though, a mouse click event would trigger all the changes. Commented Apr 1, 2014 at 22:34

5 Answers 5

1

try this...

function mouseOver() {
   document.getElementById('image').style.height = "400px";
}
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

0

Change the JS to this:

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

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

image.onclick = mouseOver;

Comments

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.