0

Example using jquery and materialize.js

Once created an element with a js code, for example:

$('#buttonA').click(function() {
 $('.container').empty;
 $('.container').prepend('<a class="button" id="buttonB" data-id="21">Second button</a>');
}

Is created a button successfully but the problem appears when I want to code something with this generated button, for example:

$('#buttonB').click(function() {
     Materialize.toast('This message is not gonna appear', 1500, 'green');
    }

Nothing will happen. Anybody knows how to make it work as a normal element? I'd be so grateful :-)

1 Answers1

0

First of all, your code has escaping issue with ": If you still have issue after fixing this, feel free to comment and I will look into it further

$("#buttonA").click(function() {
 $(".container").empty;
 $(".container").prepend("<a class=\"button\" id=\"buttonB\" data-id=\"21\">Second button</a>"); // you need to escaping "s carefully
}
Kevin Qian
  • 2,532
  • 1
  • 16
  • 26