It is not valid to have two elements with the same id
value in a single HTML document. You must give each element in the document its own unique ‘id’ value. Note that jQuery will only return (at most) a single match for an ID-based selector.
However, your selector doesn’t need to use IDs. You should be able to use something simpler, like $('select[name="People_ID"]').select2()
. This will initialize all of the <select name="People_ID">
elements that currently exist in the DOM. (If you are creating tabs dynamically—or inserting their content dynamically—then the <select>
elements you insert will not be initialized unless you call the select2()
function after you have inserted the content of the tab.)
I can’t tell from your description exactly what’s going on. Can you post sample code on codepen.io or jsfiddle.net that demonstrates your issue? You don’t need to include your actual data if it is sensitive; but a sample page that shows how you are creating and populating your tabs, and how you are initializing your Select2 widgets, would be very helpful in troubleshooting your problem.