{"id":885,"date":"2010-09-16T02:15:58","date_gmt":"2010-09-16T02:15:58","guid":{"rendered":"http:\/\/www.phpmind.com\/blog\/?p=885"},"modified":"2010-09-16T02:20:48","modified_gmt":"2010-09-16T02:20:48","slug":"how-to-change-image-with-onclick","status":"publish","type":"post","link":"https:\/\/www.phpmind.com\/blog\/2010\/09\/how-to-change-image-with-onclick\/","title":{"rendered":"How to change image with onclick?"},"content":{"rendered":"<p>To change the image using OnClick function i have found 2 ways.<\/p>\n<p>1. Using jQuery.<br \/>\n2. Normal JavaScript.<\/p>\n<p>Lets look one by one.<\/p>\n<pre lang=\"javascript\">\r\n<script type=\"text\/javascript\" src=\"http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.4.2\/jquery.min.js\"><\/script>\r\n<script type=\"text\/javascript\">\r\n$(document).ready(function(){\r\n  $(\"#ChangeImage\").click(function(){\r\n  $('#ChangeImage').attr('src','yahoo.gif');\r\n\r\n  });\r\n});\r\n<\/script>\r\n<img decoding=\"async\" src=\"bm_yahoo.gif\" name=\"my_pic\" id=\"ChangeImage\">\r\n<\/pre>\n<p>second by using simple JavaScript. I suggest not you use direct JavaScript call function. Good PHP Technology companies are not using like this.<\/p>\n<pre lang=\"javascript\">\r\n<script type=\"text\/javascript\">\r\nfunction changePic()\r\n{\r\n  document.getElementById(\"Img1\").src=\"bm_yahoo.gif\";\r\n}\r\n<\/script>\r\n<a href=\"#\" onclick=\"changePic()\";><img decoding=\"async\" border=\"0\" id=\"Img1\" src=\"yahoo.gif\" \/><\/a>\r\n<\/script>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To change the image using OnClick function i have found 2 ways. 1. Using jQuery. 2. Normal JavaScript. Lets look one by one. second by using simple JavaScript. I suggest not you use direct JavaScript call function. Good PHP Technology companies are not using like this.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[27],"tags":[],"class_list":["post-885","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/885","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/comments?post=885"}],"version-history":[{"count":5,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/885\/revisions"}],"predecessor-version":[{"id":890,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/posts\/885\/revisions\/890"}],"wp:attachment":[{"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/media?parent=885"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/categories?post=885"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.phpmind.com\/blog\/wp-json\/wp\/v2\/tags?post=885"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}