Should / How could I use .slice () to replace the image with a button on a button click? (to use next / previous button in gallery)
I'm stumped and can really help with this gallery I'm working on. I used the tutorial "4 lines jquery gallery" for me where I am now. Here's a demo of it that shows how it all works http://workshop.rs/demo/gallery-in-4-lines/
I got to the point where I would like to include the previous and previous button.
Since the images are named "1-large.jpg", "2-large.jpg", "3-large.jpg" ... etc. I tried using .slice () to move the first digit and then add 1 or minus 1, which resulted in the next / previous pic, but that didn't work at all since my javascript skills are missing and I don't even know if there is does he have a better way to get closer to him.
My question is, does the .slice () method use a path, or is there some simpler code I can use on my buttons?
Any help would be much appreciated.
source to share
If you only want the first character of the string:
var name = "1-large.jpg";
var i = name[0];
// i is now '1'
but that won't work for i> 9, so using split would be better:
var i = name.split('-')[0];
// i is now '1'
var i = "1023-large.jpg".split('-')[0];
// i is now '1023'
and convert the string to int:
var num = parseInt("23", 10);
// num is now the number 23, not a string
source to share