I'm trying to set up a tracking system that uses a data value for holding an event type. My HTML looks like this:
<a href="#articles" class="track" data-track="article_search_results">Articles</a>
<a href="#books" class="track" data-track="books_search_results">Books</a>
<a href="#notes" class="track" data-track="notes_search_results">Notes</a>
And the JQuery looks like this:
$(document).delegate('.track', 'click', function(e) {
console.log($(this));
console.log($(this).data("track"));
});
Using every element that has the class .track, I'm trying to get the data-track value from it, but it always returns undefined. What am I doing wrong?
UPDATE
I have icons in my code which is causing the problem:
<a href="#articles" class="track" data-track="article_search_results"><i class="icon-pencil"></i></a>