Studying the diff of I noticed that some templates of base/default package gained data-action attribute (see here). However I didn't found any usage of it in JS files.

Is there any reason this attribute was added? My first guess was there is some HTML5 feature I'm not aware of that is using data-action but quick googling showed nothing.

  • 3
    I invested like 5 minutes in searching for a reason but nothing...I say remove them and see what happens. Then tell us. :) – Marius Jun 4 '14 at 6:56
  • Well, we just discussed it with @benmarks yesterday that removing stuff required way more concerns and tests then adding new features. – user487772 Jun 4 '14 at 7:17
  • I only know one reason to add data-* to things and this is jQuery. Maybe the template is backported from Magento 2? – Fabian Blechschmidt Jun 4 '14 at 7:17
  • Grrr. When they will become mature. Just anyone post the answer that this is crap which will be later called with the noble word "legacy" and I will accept the answer. – user487772 Jun 4 '14 at 7:19

I believe this is due to the shift that Magento is making towards jQuery. Adding in specific data attributes will allow jQuery to easily interact with the objects. I can't be certain about this as there's been no information provided from Magento regarding the additional markup.

This would also allow front-end developers to drastically change the classes & IDs without effecting jQuery's interaction with them (providing they left in the data-action).

There's an example of the data-action being used (without jQuery in this instance) on this page: http://javascript.info/tutorial/event-delegation

<div id="menu">
  <button data-action="Save">Click to Save</button>
  <button data-action="Load">Click to Load</button>

function Menu(elem) {
  this.onSave = function() { alert('saving') }
  this.onLoad = function() { alert('loading') }

  var self = this

  elem.onclick = function(e) {
    var target = e && e.target || event.srcElement
var action = target.getAttribute('data-action')
    if (action) {

new Menu(document.getElementById('menu'))

I make this assumption from the addition of jQuery being added in Magento 2.

  • Well, there's still no jQuery in M1. – user487772 Jun 4 '14 at 8:39
  • @Tim this was an educated guess as they've implemented it into M2. Maybe they're trying to familiarise the elements across the versions. – Dave Jun 4 '14 at 8:56
  • I guess they were just lazy to look at the diff as templates in M1 and M2 are not compatible a priori. – user487772 Jun 4 '14 at 9:05
  • Anyways, your answer will be clearer if you will add your M2 assumtion to it. – user487772 Jun 4 '14 at 9:06
  • @Tim, I wouldn't say that M1 has no jQuery, given the rwd theme seems to use it, but granted this doesn't explain why it would be in the base template, nor indeed does that particular data attribute appear to be used. – Peter O'Callaghan Jun 4 '14 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.