Search code examples
jqueryimagetitlefill

Fill in Input Field by Clicking Image (title) with JQuery


My html looks like this

<input type="search" id="starSearch" />
<img src="image.png" title="How to do this">

How can I change this script that will fill search field with image title attribute value? I know this code, but it's for links and innerHTML only

 $(function(){
    $('.special_field_link').live('click', function() {
        $("#a_input_id").val($(this).html());
    });
});

Solution

  •  $(document).ready(function() {
       $('img').click(function(){
        $('#starSearch').val($(this).attr('title'));
      })
    });​
    

    Demo : http://jsfiddle.net/gopalrohila/vzZ22/