0

I'm using a jQuery plugin that requires me to bind an event to a class on a button.

The button is repeated in a table like so:

<tr v-for="option in app.options">
  <td>{{ option.value1 }}</td>
  <td>{{ option.value2 }}</td>
  <td><button class="btn btn-primary next">Choose</button></td>
</tr>

However, when it renders the options (which are not set to begin with, they're set via an http request), and the button is clicked, the jQuery event isn't registered on the button even though it has the next class attached to it.

How can I get jQuery to recognize the button with the .next class when it's rendered by Vue.js?

1 Answer 1

1

As the other answer states, it probably isn't registering the event because the next button doesn't exist at that point. I would use a vue directive to call a method on your component, then manually fire the jquery event within that method. So your button would be <td><button class="btn btn-primary next" v-on:click="fireJqueryEvent">Choose</button></td>

Then in your Vue component:

methods:{
    fireJqueryEvent(e){
        //run the function you need to run or use .trigger() to fire an event
    }
}

You could also wait until the Vuejs content has loaded before you call your jquery wizard.

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.