Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Russell Atkins
3,921 PointsTrying to see if I can run a jQuery .each on a "data-event-category" (google autotrack variable inside of an Anchor (a)
In drupal, I am running a google analytic tracking of views slideshow anchor links.
<a href=" <?php print $fields['entity_id_3']->content?>" data-on="click" data-event-category="Read_More" data-event-action="slider"> Read More</a>
I want to append the data-event-action to read data-event-action="slider1" (slider 2 etc.)
My best attempt so far is
$('slider_Read_More').each(function(index) { $(this).append('slider' + index); });
Any suggestions?
2 Answers
Steven Parker
243,656 PointsYou might not be using the correct jQuery methods and arguments:
- you're using
'slider_Read_More'as a tag name selector, but it's not a tag name - you call append but the argument is not an element
- your intention is just to add an attribute but you did not name it
If I understand your intentions correctly, you might have better luck with something like this:
$('a[data-event-category="Read_More"]').each(function(index) {
$(this).attr('data-event-action', 'slider' + index);
});
Russell Atkins
3,921 PointsSteven Thank you so much!! Um... I'm not seeing the data-event-categories in google analytics but I don't think its the fault of your amazing code! Thank you!