3

I am working on JavaScript add-on. while trying to read HTML loaded on the browser via chrome's developer tool -> element tab.

the code was executing fine. but I can't see attribute. it is a just simple custom attribute, right?

this question is only for the knowledge base.

enter image description here

on save button there should have extra attribute "data-mage-init" which help to execute some javascript.

3
  • 2
    check by view source(Ctrl + U).
    – kunj
    Commented May 23, 2018 at 13:24
  • @kunj thanks it worked. but do you know why it not working in element tab? is it bug from chrome? FireFox also don't show "data-mage-init" in inspector. Commented May 23, 2018 at 13:55
  • Not Sure about it but Magento call this js for that vendor/magento/module-ui/view/base/web/js/lib/knockout/bindings/mage-init.js And this file calls this one. lib/web/mage/apply/main.js Main JS process for data-mage-init and I think remove that attribute from HTML.
    – kunj
    Commented May 23, 2018 at 14:09

1 Answer 1

7

Magento removing that data-mage-init attribute from lib/web/mage/apply/main.js this file and from this function:

function getData(el) {
        var data = el.getAttribute(dataAttr);

        el.removeAttribute(dataAttr);

        return {
            el: el,
            data: JSON.parse(data)
        };
    }

You can see el.removeAttribute(dataAttr); code in that function.

I think Magento removing that for security and minify HTML. Maybe there are other reasons for that.

1
  • 1
    That is correct +1. Commented May 23, 2018 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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