I am working with searching string from database and selected string appending to the text box
I can get the search results from database and i can append the result below the textbox.
But my problem is onclick of particular result I can't get the "id" of appended result
My code looks like this..
<span id="new">
<input id="addSearch" type="text" width="50px"/>
</span>
<div id="append" style="margin-top: -11px;width: 149px;"></div>
<script type="text/javascript">
$(function(){
$("#addSearch").keyup(function() {
var v = $('#addSearch').val();
$.getJSON('http://localhost/api/getresult/?q='+v, function(data){
$('#append').html('');
$.each(data, function (key,value){
$('<div id='+value["id"]+' class="searchResult">
'+value["name"]+'
</div>').appendTo($('#append'));
});
});
});
});
$('.searchResult').click(function(){
alert($(this).attr("id"));
});