Solved

Alternative way of calling javascript function

Posted on 2013-06-11
5
254 Views
Last Modified: 2013-06-12
I barely ever code any more but of course ever now and then I get curious. I saw this code and I'm not sure how it works? I'm curious about the data-omni variables. Obviously it is calling some function and passing an argument to it but how does it work? Where do I find the function it is calling? I've never seen a function called in this manner before?

<a href="//store2.origin.com/store/ea/en_US/buy/productID.257620200"
title="" class="btn btn-fifa"
data-omni-event='retailerClick'
data-omni-args="purchase_click_origin_xbox360">
Pre-order
</a>
0
Comment
Question by:894359
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 58

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39240214
The link is storing meta data using the html5 user data attributes. Anything prefixed by data- is definied as user defined data.

I would imagine there is an event handler (JQuery or plain JS) bound to the click of that <a> that then picks up those attributes and does something with them

Example
$(function() {
  $('a').click(function(e) {
    e.preventDefault(); // If we don't want the normal click away from page to fire
    var event = $(this).attr('data-omni-event'); // event now contains 'retailerClick'
    var args = $(this).attr('data-omni-args'); // args now contains 'purchase_click_origin_xbox360'

   $.post('tosomeurl.php', {event: event, args: args}, function(response) {
     // do something with the response.
   });
  });
});

Open in new window

0
 

Author Comment

by:894359
ID: 39240228
anyway to figure out what this is bound to?
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39240353
0
 

Author Closing Comment

by:894359
ID: 39241986
Thanks a million! Much appreciated!
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 39242088
You are welcome - thanks for the points.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question