Skip to content

Trigger event on opening and closing tabs

December 30, 2013

Firstly, hope everyone had a good Christmas and look forward to more posts next year!

Secondly, apologies for the absence of new posts, the last two months have been extremely busy for me building web systems for the company, and today post-Christmas has essentially been a free day!

I would like to write a common issue which I had building using JQuery Mobile, and that is accordions. You may or may not of used them, but they are essential for opening and closing sections of writing especially for the use of displaying terms and conditions for example. Here is some useful code using the event handler ‘trigger’ to open and close an accordion tab in JQM.

        $(“a.policy”).bind(‘click’, function(e) {
            $(‘.policytab’).trigger(‘expand’);
        });

        $(“a.terms”).bind(‘click’, function(e) {
            $(‘.termstab’).trigger(‘expand’);
            $(‘.policytab’).trigger(‘collapse’);
        });

Notice here that I have added the ‘click’ event which binds to the a link with class policy and expanded the accordion tab using the trigger event with value “expand”. Likewise, I can close this tab if fpr example I bind to another a link with class terms.

Hope that helps!

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: