1

From a jQuery gallery lightbox I have in html, the #imageGallery id

I want to have severals lightboxes so I changed the id to class, both in html and css.

How can I change it in javasctipt ? I have this code refering to the particulart id :

var glength = $('#imageGallery li').length;
$('#imageGallery a').click( function(event)
$('#imageGallery a').not(this).removeClass('active')
('#imageGallery li').first().find('img').trigger('click')
$('#imageGallery li').last().find('img').trigger('click');

Thanks in advance

1
  • use . for class # for id .. #imageGallery to .imageGallery Commented Jan 13, 2019 at 2:55

1 Answer 1

1

use . for class # for id .. #imageGallery to .imageGallery this is just for how to select class .. but I'm sure you'll need a lot of things to make the code works for several lightboxes .. see the next code may help

$('.imageGallery a').click( function(event){   // when click on <a>
  var Get_Lis = $(this).closest('.imageGallery').find('li'); // get the li's in the same `imageGallery`
  var glength = Get_Lis.length; // get number of li's
  $(this).closest('.imageGallery').find('a').not(this).removeClass('active'); // change all but this
  Get_Lis.first().find('img').trigger('click');  // for first li
  Get_Lis.last().find('img').trigger('click');   // for last li
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your fast answer. I made these changes but there is something more needed. This is the javascript code I want to change to javascript (to long to full post it here) codepen.io/olivertaylor/pen/oxQYNm

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.