Autocomplete Search with Image and Custom HTML in jQuery


Today I will show you on your website to set an autocomplete jquery example with an image. generally, you utilize autocomplete in jquery with designation, email, message, etc. text but if you optate to integrate images or your own HTML code like utilizer HTML tag in autocomplete then you have to utilize "_renderItem" in jquery UI. how you will engender I give you an example of an HTML file :

        <title>Autocomplete With Images -HackTheStuff</title>
        <link rel="stylesheet" href="">
        <h1>Autocomplete With Images -HackTheStuff</h1>
        <div class="ui">  
            <label for="name">Name: </label>  
            <input id="name">  
        <script src=""></script>  
        <script src=""></script>  
            $(function() {  
              $( "#name" ).autocomplete({  
                source: function( request, response ) {  
                   url: "http://yourwebsitepath/getdata",  
                   dataType: "json",  
                   data: {  
                       term: request.term  
                   success: function( data ) {  
                       response( $.map( data.results, function( result ) {  
                           return {  
                               label: + " - " + result.label,  
                               imgsrc: result.image  
              }).data( "ui-autocomplete" )._renderItem = function( ul, item ) {  
                  return $( "<li></li>" )  
                      .data( "item.autocomplete", item )  
                      .append( "<a>" + "<img style='width:25px;height:25px' src='" + item.imgsrc + "' /> " + item.label+ "</a>" )  
                      .appendTo( ul );  

i hope you like this.