javascript - Jquery not working while process dynamically -


the below code works me

function gethotelsbydestination(dest_id) {    $.ajax({          url: "controller/gethotels.php",          datatype: "json",          data: "id=" + dest_id,          success: function(data) {               $("#divid").html("");               $.each(data, function(index, item) {                   var val = item.id;                   var text = item.name;                       $("#divid").append(                       $('<option></option>').val(val).html(text)                        );               })          }    }); } 

but when use below code not returns anything.divv id of dropdown passed php page

function gethotelsbydestination(dest_id, divv) {      var divdrp = "$('#" + divv + "')";     $.ajax({          url: "controller/gethotels.php",          datatype: "json",          data: "id=" + dest_id,          success: function(data) {              divdrp.html("");              $.each(data, function(index, item) {                  var val = item.id;                  var text = item.name;                  divdrp.append(                       $('<option></option>').val(val).html(text)                  );              })          }     }); } 

the problem var divdrp="$('#"+divv+"')"; solution please

you can't concatenate directly. use this:

divdrp = $('#' + divv); 

instead of this:

var divdrp = "$('#" + divv + "')"; //  not jquery object  

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -