0

I am dealing with strange issue, but that should be a simple solution as my mind totally stuck I don't know where I am going wrong, simply I want to put my function thrice as shown below in example:

If my function is :

function(){
    if (jQuery('#gallery-v').length) {
        var $container = jQuery('#gallery-v');
        alert($container);
        $container.imagesLoaded( function(){
            $container.isotope({
                filter: '*',
                animationOptions: {
                    duration: 750,
                    easing: 'linear',
                    queue: false
                }
            });
        });
        jQuery('#filterlist_v a').click(function() {
            alert(this);
            jQuery('#filterlist_v .current').removeClass('current');
            jQuery(this).addClass('current');

            var selector = jQuery(this).attr('data-filter');
            $container.isotope({
                filter: selector,
                animationOptions: {
                    duration: 750,
                    easing: 'linear',
                    queue: false
                }
            });
            return false;
        });
    }
}

I simply want it to be two times more by just incrementing my selector value like '#gallery-v' to '#gallery-v1' and for '#filterlist_v a' to '#filterlist_v1 a' just simply increment my gallery-v by 1 in first iteration 2 in second and so on etc ...

Here is my code which I tried:

var count = 2;
for(var i = 0; i < count; i++){
 function(){
        if (jQuery('#gallery-v' +i +'').length) {
            var $container = jQuery('#gallery-v' +i +'');
            alert($container);
            $container.imagesLoaded( function(){
                $container.isotope({
                    filter: '*',
                    animationOptions: {
                        duration: 750,
                        easing: 'linear',
                        queue: false
                    }
                });
            });
            jQuery('#filterlist_v' +i +' a').click(function() {
                alert(this);
                jQuery('#filterlist_v +i +' .current').removeClass('current');
                jQuery(this).addClass('current');

                var selector = jQuery(this).attr('data-filter');
                $container.isotope({
                    filter: selector,
                    animationOptions: {
                        duration: 750,
                        easing: 'linear',
                        queue: false
                    }
                });
                return false;
            });
        }
    }
}

but its not printing my code in my js file as I wanted :( what's going on wrong please ???

0

1 Answer 1

1

In your html code you should change id's of elements to #gallery-v0 and #filterlist_v0 because in the first loop (i === 0) you get selectors:

'#gallery-v' + i + '' -> #gallery-v0
'#filterlist_v0' + i + '' -> filterlist_v0 

You have another error here: '#filterlist_v +i +' .current', it should be '#filterlist_v' + i + ' .current'. Assuming that first part of code works, that would be works.

Sign up to request clarification or add additional context in comments.

6 Comments

I could not underswtand your words
errors will be removed for sure, but you have not gotten my point I think this thing (jQuery('#gallery-v' +i +'').length) should become (jQuery('#gallery-v0').length) in first iteration and (jQuery('#gallery_v1').length) in second iteration and so on etc ... i just want to get those selectors from my html page which are living there
and why should i change my id's ? any issue for that ? as I am getting i value in the loop with out any issue
Ok, I thought that you have element with id #gallery-v in your code and try to get it with this loop, so what is the problem? Is the first part of code working?
I have #gallery-v0, #gallery-v1, #gallery-v2 in my html ... but I want to have function which filters those html based on each id ... i mean function for every individual item from html like a function for #gallery-v0, then 1 function for #gallery-v1 and last for #gallery-v2 etc ... hope you get it now
|

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.