0

For example, I have a page1.html with this code:

<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>page1</title>
</head>
<body>
 <select style="width:100%" class="select2">
  <option value="AK">Alaska</option>
  <option value="HI">Hawaii</option>
 </select>
</body>
</html>

and have a myscript.js

$('.select2').select2({
  allowClear : true,
  width : '100%'
});

Now, I want to load dynamically select2.min.js where .select2 class located. what should I do?

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
  • 1
    As it appears you're using jquery, have a look at [jQuery.getScript()](https://api.jquery.com/jquery.getscript/) for loading scripts. – Phil Cooper Oct 18 '15 at 08:35

1 Answers1

0

Possible duplicate of questions:

Clear dropdown using jQuery Select2

Select2 allowClear not working with dynamic dropdown list

and many more... If not, please explain more regarding the functionality you are trying to achieve.

If you want to load that particular script into the page dynamically, then Ajax is the way - but is not loaded 'where .select2 class located'.

Community
  • 1
  • 1
Steve Padmore
  • 1,710
  • 1
  • 12
  • 18
  • this is incorrect, you don't understand completely. select2 plugin is example. I want to load plugin.min.js each script dynamically –  Oct 18 '15 at 11:31
  • Can you provide the scenario please. Why and where it needs to be loaded, and what change it should make to what part of the UI when it is. You have stated you want to load a script into a class attribute... – Steve Padmore Oct 18 '15 at 11:39