Skip to content

How to change href on an a link and dynamically change this using pageshow

April 26, 2013

A very very useful event handler that I have found in JQuery Mobile is the pageshow. It’s useful for when you want to update something inside a function due to a page cahnge or page transition. It acts as a response to a page change and becomes active. Here I wrote code that can update the href link of a#register if you switch between the home page and the register page which changes to #registerpage and #homepage respectively!

  $(document).ready(function() {
            
            $(‘#homepage’).on(‘pageshow’, function() {
                $(“a#register”).attr(‘href’, ‘#registerpage’);
            });
            
            $(‘#registerpage’).on(‘pageshow’, function() {
                $(“a#register”).attr(‘href’, ‘#homepage’);
            });

});

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: