1

In jQuery I can bind event to dynamically created child element:

$(staticAncestors).on(eventName, dynamicChild, function() {});

For example, I have table and want to append new row, when user places focus in the last row input:

$("#meta-panel").on("focus", ".input-row:last input", function (event)   {
    myVueApp.addMetaInputRow(); //pushes new row into array
});

How can I achieve this with Vue?

1 Answer 1

2

your new html is required to be compiled bu vue to behave like part of vue instace.

myVueApp = new Vue({
  methods: {
    addMetaInputRow: function(){
      // here you can add method which can focus on last row       
      var $element = $('#app').append('<div onClick="dynamic()">HTML code.</div>')
      this.$compile($element.get(0));
    },
    dynamic() {
      // add new elements to rows
      console.log('hello from dynamic content.')
    }
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.