Autocomplete with images and custom html code in Jquery UI?

Today now in this blog I will show you how to autocomplete with image and custom html code in jquery Ui. If in your website you need to set auto-complete user or full-name also with image. Now in generally we can use auto-complete also with name, email, message etc text but if we want to add image or our own html code as like as user html tag in autocomplete then we need to use “_renderItem” in jquery ui. Here we know how we will create because here i give you example of html file :

<title>How To Use Autocomplete</title>  
    <link rel="stylesheet" href="">  
    <script src=""></script>  
    <script src=""></script>  
     $(function() {  
       $( "#name" ).autocomplete({  
         source: function( request, response ) {  
            url: "http://yourhostpath/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 );  
    <div class="ui">  
      <label for="name">Name: </label>  
      <input id="name">  

Read Also : How to Open Link in New Tab on Click in javascript ?

Thanks for read this, I hope it will you. You can also follow us onĀ Facebook.


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →