samedi 9 juillet 2016

Variables inside of selectors

I saw a bunch of other threads that ask how you can combine variables with jQuery selectors, things like $('.middle', $top) to get whatever $top is if it's inside of .middle.

What I'm looking for is how to combine them like this:

var gallerymodal_number = $(this).attr('data-gallerynumber');

So say that gallerymodal_number ends up being a value of 2.

My code works if I just literally write out:

var galleryitem = '*[data-galleryitem="2"]';

But I need to get it via the variable above.

So my question is how do I do something like this:

var galleryitem = $('*[data-galleryitem="' + gallerymodal_number + '"]');

I just get an object returned with that particular code.

Aucun commentaire:

Enregistrer un commentaire