Naota
Naota

Reputation: 668

JQuery how to run script on button press

What I'm doing is making a theme with two layouts, which are changeable by button press, from standard blog layout to a gallery layout etc.

However I wan't to run the infinite scroll script when the button is pressed for the gallery layout, everything works except for infinite scroll.

How can I run another script along with this? Kinda like taking away the <!-- / --> around a script to activate it, if you know what I mean.

$("a.button").toggle(function() {
        $(this).addClass("toggle");
        $("div.posts").fadeOut("fast", function() {
            $(this).fadeIn("fast").addClass("gallery");
        });
    }, function() {
        $(this).removeClass("toggle");
        $("div.posts").fadeOut("fast", function() {
            $(this).fadeIn("fast").removeClass("gallery");
        });
    }); 
});

Upvotes: 2

Views: 643

Answers (3)

Ahsan Rathod
Ahsan Rathod

Reputation: 5505

If you want to use <a> tag then you have to use:

$('a').click(function(){
    ... scroll code...
});

and if you want to access it by an ID then use like this:

   $('#anyId').click(function(){
    ... scroll code...
});

Upvotes: 1

unclenorton
unclenorton

Reputation: 1625

It would be better if you initialize both layouts on page load (DOM Ready) and just toggle them via CSS display property. The main reason for that is that you wouldn't need to re-initialize the infinite scroll object each time, and destroy it when user toggles back to blog style.

Upvotes: 1

meteorainer
meteorainer

Reputation: 952

$('.gallery').click(function(){
    ... scroll code...
});

Adding a click listener just to the gallery class. Will that work?

Upvotes: 0

Related Questions