Moorberry
February 6, 2013

Clicked Link Attributes in jQuery Mobile Events

Posted on February 6, 2013  •  1 minutes  • 111 words

So…are you tired of writing and rewriting (or commenting out) Javascript and want to handle your clicked link attributes inside of a jQuery Mobile event? Here’s how:

var params = {};

$('a').live('click', function(event)
{
  $.each($(event.target)[0].attributes, function(key, value){
    params[value.name] = value.value;
  });
});

$('div[data-role="page"]').live('pageshow',function(event, ui)
{
 console.log(params)
});

The click event has to be done separately and parsed before the pageshow event takes place.

Doing things this way you can also take full advantage of the rest of jQuery Mobile’s special page responsive events that happen throughtout the life of your application.

Please, if you have any ideas for an alternative method of injecting clicked link attributes into event functions, comment below.

comments powered by Disqus
Follow me

I work on web & mobile application development, data integration, and AI.