javascript gallery not displaying main image when thumbnails clicked

moonshineOutlaw

I'm wanting to create a gallery which displays a main image when the thumbnails are clicked. When clicked the thumbnails rather than altering the image in the webpage take the user to the file where the image is kept and display it in the top right corner.

No idea why this is happening ? Any suggestions where I'm going wrong and how to fix this ?

<img id="veiwer" src="images/motorbike-girl.jpg" />
<div id='thumbs'>
   <a href='images/chicks.jpg' onclick="gallery(this);"><img src='images/chicks-
   thumb.jpg'/></a>
   <a href='images/motorbike-girl.jpg' onclick="gallery(this);"><img 
   src='images/motorbike-girl-thumb.jpg'/></a>                                                
   <a href='images/yamaha-thumb.jpg' onclick="gallery(this);"><img              
   src='images/yamaha.jpg'/></a>    
</div>


         function gallery(change) {

          document.getElementById('viewer').src = change.href;
         }
Laurent S.

The problem occurs because of the default behavior of the anchor tag : by default, when you click a link, you get to the page/document it's pointing to. So, in your javascript you would need to tell "Don't run the default behavior, only what I want to do". It's done through the preventDefault() method of the event.

cfr this fiddle for a working example, where I removed also the inline javascript (= onclick attribute).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Image gallery thumbnails

From Dev

lists of links when clicked pops up an image gallery using fancybox

From Dev

How to have img popout when containing div is clicked (Image gallery)?

From Dev

How to make sort gallery thumbnails image by date

From Dev

jQuery basic slider into image gallery with thumbnails

From Dev

How to make sort gallery thumbnails image by date

From Dev

Image cropped when picked from gallery but not cropped when clicked from camera

From Dev

insert image when button is clicked html javascript

From Dev

Image gallery displaying images too slow

From Dev

How clear gallery thumbnails after deleting image from DCIM in Android

From Dev

How clear gallery thumbnails after deleting image from DCIM in Android

From Dev

event delegation click on thumbnails not showing main image

From Dev

Advance slick slider when image in gallery is clicked (multiple slick sliders on one page)

From Dev

Displaying Item when i clicked it

From Dev

Issue displaying image in main activity

From Dev

How to handle: When image is clicked identical image generated using Javascript

From Dev

blueimp Gallery borderless thumbnails

From Dev

Photo Gallery Thumbnails Resizing

From Dev

Accessing the image gallery through code for displaying in image view

From Dev

JavaScript code for my Image Gallery

From Dev

Javascript splice for filtering image gallery

From Dev

CSS trick for avoiding extra class when displaying thumbnails

From Dev

Javascript: Changing an image on click and then back to original when clicked again

From Dev

Fancybox for the second gallery group displaying only one image

From Dev

Javascript Adding two input values together and displaying answer in third when button clicked

From Dev

JavaScript and Bootstrap image gallery with different image sizes

From Dev

Displaying password only when the button is clicked in PHP

From Dev

Displaying decimal numbers when button is clicked in swift

From Dev

saving image clicked from camera or loaded from gallery in database and retrieving it

Related Related

  1. 1

    Image gallery thumbnails

  2. 2

    lists of links when clicked pops up an image gallery using fancybox

  3. 3

    How to have img popout when containing div is clicked (Image gallery)?

  4. 4

    How to make sort gallery thumbnails image by date

  5. 5

    jQuery basic slider into image gallery with thumbnails

  6. 6

    How to make sort gallery thumbnails image by date

  7. 7

    Image cropped when picked from gallery but not cropped when clicked from camera

  8. 8

    insert image when button is clicked html javascript

  9. 9

    Image gallery displaying images too slow

  10. 10

    How clear gallery thumbnails after deleting image from DCIM in Android

  11. 11

    How clear gallery thumbnails after deleting image from DCIM in Android

  12. 12

    event delegation click on thumbnails not showing main image

  13. 13

    Advance slick slider when image in gallery is clicked (multiple slick sliders on one page)

  14. 14

    Displaying Item when i clicked it

  15. 15

    Issue displaying image in main activity

  16. 16

    How to handle: When image is clicked identical image generated using Javascript

  17. 17

    blueimp Gallery borderless thumbnails

  18. 18

    Photo Gallery Thumbnails Resizing

  19. 19

    Accessing the image gallery through code for displaying in image view

  20. 20

    JavaScript code for my Image Gallery

  21. 21

    Javascript splice for filtering image gallery

  22. 22

    CSS trick for avoiding extra class when displaying thumbnails

  23. 23

    Javascript: Changing an image on click and then back to original when clicked again

  24. 24

    Fancybox for the second gallery group displaying only one image

  25. 25

    Javascript Adding two input values together and displaying answer in third when button clicked

  26. 26

    JavaScript and Bootstrap image gallery with different image sizes

  27. 27

    Displaying password only when the button is clicked in PHP

  28. 28

    Displaying decimal numbers when button is clicked in swift

  29. 29

    saving image clicked from camera or loaded from gallery in database and retrieving it

HotTag

Archive