Hello,
If there is an element on the page to which the jQuery plugin binds (for example, select2), then the plugin works. If an element is created by a script, then the plugin is not bound to it. How to connect plugins to dynamically created elements? (In the example, clicking on the "add select" button creates a new drop-down list, but the plugin is not connected to it)
$(document).ready(function() { $("select").select2(); $("input[type=button]").on('click',function(){ $("div").append('<select><option>1</option><option>2</option><option>3</option><option>4</option></select>'); }); }); <link href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet" /> <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script> <div> <input type="button" value="Add select"/> <br/> <select> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> <select> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> </div>