Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2017
    Thanked 0 Times in 0 Posts

    Post Using Javascript to change the src in a line of Javascript?

    Fyi, I'm new to JS.

    My original code works when I click a small image, JS changes the display of a big image that's fixed from none to block. I want to do this with all the images on my page, and I was told my by teacher that it's possible with just a few lines of code. I tried to figure it out on my own but it doesn't seem to work / it's not possible.

    This is my code.

    JS: function largeone() {


    <div id="largeforestone">
    <img src="forest1large.jpg">

    <img onmouseup="largeone()" src="./images/forest1.jpg">

    At the moment it's working fine.

    So I thought if I put the src in "largeone('./images/forest1large.jpg') and added another JS code with
    window.document.getElementById('largeforestone').body.src="largeone()"; It would work, but it didn't. And I'm not sure what I need to fix or if it's possible this way?

    Any help would be greatly appreciated.

  2. #2
    Regular Coder
    Join Date
    Feb 2016
    Thanked 187 Times in 185 Posts
    I'm not shure if I understand you correctly: Do you want to display the large version of your images in the same container div#largeforstone?


Tags for this Thread

Posting Permissions

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