Last post Sep 19, 2018 01:22 PM by mgebhard
Sep 19, 2018 11:18 AM|ldoodle|LINK
I am doing this:
var elem = $( this );var itemid = elem.closest( "li, .tile, .modal" ).data( "itemid" );var tile = $( ".tile[data-itemid='" + itemid + "']" );
var modal = $( ".modal[data-itemid='" + itemid + "']" );// do something with tile object// do something else with modal object
Now, I want to do something with both the tile object and modal object at the same time, so rather than re-referencing the object again like this, is there a better way?
var elems = $( ".tile[data-itemid='" + itemid + "'], .modal[data-itemid='" + itemid + "']" );
// do something with elems object -- this works with more than one tile or modal
I tried using the existing variables in square brackets, but this only targets the first of each object. There could be more than one tile or modal
$( [tile, modal] ).find( do something );
Sep 19, 2018 01:22 PM|mgebhard|LINK
An array is made up of items. You must loop over the array apply whatever logic you wish to each element of the array.
See the jQuery API docs for more information.