how to use text onclick to display images in javascript

JavaScript
$('img').click(function () { // on a click
  if($(this).attr('id') == '1') { // get the id attribute
    $('#div').html('Image with 1 was clicked'); // write the text
  } else { // else if
     // write something else for the 2
  }
}$('img').click(function () { // on a click
  if($(this).attr('id') == '1') { // get the id attribute
    $('#div').html('Image with 1 was clicked'); // write the text
  } else { // else if
     // write something else for the 2
  }
}$('img').click(function () { // on a click
  if($(this).attr('id') == '1') { // get the id attribute
    $('#div').html('Image with 1 was clicked'); // write the text
  } else { // else if
     // write something else for the 2
  }
}
Source

Also in JavaScript: