How to solve Uncaught TypeError: undefined is not a function
Hi,
Can someone help me understand how to solve the error mentioned in the title?
I have a dynamically generated select element with a couple of option values inside. Next the select element, is a button. When I click the button, I want jQuery to tell me whether or not I have selected only one option value or multiple values (array or not).
This is the jQuery code:
<script type="text/javascript">
$(document).ready(function() {
/*Detecting events on dynamically generated elements
* does not work if you do not bind the event on the parent element
*/
$('#content').on('click', '#envoiSuperUsers', function() {
var superutilisateurs = $('#superusers').val(); // simple value or array of elements
if($.is_array(superutilisateurs)){
console.log('You have an array');
}else{
console.log('You have not an array');
}
});
});
</script>
Note that $('#content') is a div element updated by current html code (see below plz) in another jquery code not mentionned here.
The div#content gets next html code inside after a previous javascript event. Among other things, the generated code contains the button that triggers the above error after click
div#content contains this html code:
<div class="form-group"><label for="superusers" class="control-label col-sm-2">Les superviseurs</label>
<div class="col-sm-4">
<select class="form-control" id="superusers" multiple="multiple" name="superusers[]">
<option value="dbarikore">Didace BARIKORE</option>
<option value="divine">Divine KANEZA</option>
<option value="dmatabura">David MATABURA</option>
<option value="endikuma">Emmanuel NDIKUMANA</option>
<option value="espenaha">Espérance NAHAYO</option>
<option value="fmanirambona">Ferdinand MANIRAMBONA</option>
<option value="ghavyarimana">Germaine HAVYARIMANA</option>
<option value="jeanineK">Jeanine KEZA</option>
<option value="nisubire">Jean pierre NISUBIRE</option>
<option value="niyukurijc">Jean Claude NIYUKURI</option>
<option value="nziisaie">Isaïe NZISABIRA</option>
</select>
</div>
<button type="button" class="btn btn-primary" id="envoiSuperUsers">Autoriser</button> <button type="button" class="btn btn-danger" id="supprimerSuperUsers">Refuser</button>
</div>
Thank you in advance for your help