{"id":16137,"date":"2022-10-14T09:02:42","date_gmt":"2022-10-14T03:32:42","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/"},"modified":"2022-10-14T09:02:42","modified_gmt":"2022-10-14T03:32:42","slug":"solved-add-link-to-each-image-with-jquery-closed","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/","title":{"rendered":"[Solved] add link to each image with jquery [closed]"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-48381181\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"48381181\" data-parentid=\"48381092\" data-score=\"2\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>This should do as you want:<\/p>\n<pre><code>$(\"div .copy-url\").each(function() {\n  var imgval = $(this).find('.copy-url').val();\n  var sharer = \"&lt;a class=\"share\" href=\"\"+imgval+\"\"&gt;share&lt;\/a&gt;\";\n  $(this).append(sharer)\n});\n<\/code><\/pre>\n<p>You had the following mistakes:<\/p>\n<ul>\n<li>\n<p>You had mismatching quotes in <code>\"&lt;a class=\"share\"&gt;\"<\/code> should be <code>\"&lt;a class=\"share\"&gt;\"<\/code><\/p>\n<\/li>\n<li>\n<p>In the line <code>$('.copy-url').val<\/code> you are missing <code>$(this).find<\/code> and <code>()<\/code> after your .val. Should be <code>$(this).find('.copy-url').val()<\/code><\/p>\n<\/li>\n<li>\n<p>You have no <code>div<\/code> with the class <code>copy-url<\/code> in your code.<\/p>\n<\/li>\n<\/ul>\n<p><strong>Demo<\/strong><\/p>\n<\/p>\n<div class=\"snippet\" data-lang=\"js\" data-hide=\"true\" data-console=\"true\" data-babel=\"false\">\n<div class=\"snippet-code snippet-currently-hidden\">\n<pre class=\"snippet-code-js lang-js prettyprint-override\"><code>$(document).ready(function() {\r\n  $(\".copy-url\").click(function() {\r\n    $(this).select();\r\n    document.execCommand(\"copy\");\r\n  })\r\n\r\n  if (true) { \/\/will be replaced by navigator.share, value will be url\r\n    $(\"div\").each(function() {\r\n      var imgval = $(this).find('.copy-url').val();\r\n      var sharer = \"&lt;a class=\"share\" href=\"\"+imgval+\"\"&gt;share&lt;\/a&gt;\";\r\n      $(this).append(sharer)\r\n    });\r\n  }\r\n\r\n});<\/code><\/pre>\n<pre class=\"snippet-code-html lang-html prettyprint-override\"><code>&lt;script src=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/2.1.1\/jquery.min.js\"&gt;&lt;\/script&gt;\r\n&lt;div&gt;&lt;input type=\"text\" class=\"copy-url\" value=\"222222\" readonly=\"yes\"&gt;\r\n  &lt;span class=\"share\"&gt;copy&lt;\/span&gt; &lt;\/div&gt;\r\n\r\n&lt;div&gt;&lt;input type=\"text\" class=\"copy-url\" value=\"333333\" readonly=\"yes\"&gt;\r\n  &lt;span class=\"share\"&gt;copy&lt;\/span&gt;&lt;\/div&gt;\r\n\r\n&lt;div&gt;&lt;input type=\"text\" class=\"copy-url\" value=\"444444\" readonly=\"yes\"&gt;\r\n  &lt;span class=\"share\"&gt;copy&lt;\/span&gt;&lt;\/div&gt;\r\n\r\n&lt;div&gt;&lt;input type=\"text\" class=\"copy-url\" value=\"555555\" readonly=\"yes\"&gt;\r\n  &lt;span class=\"share\"&gt;copy&lt;\/span&gt;&lt;\/div&gt;\r\n\r\n&lt;div&gt;&lt;input type=\"text\" class=\"copy-url\" value=\"666666\" readonly=\"yes\"&gt;\r\n  &lt;span class=\"share\"&gt;copy&lt;\/span&gt;&lt;\/div&gt;<\/code><\/pre>\n<\/div>\n<\/div><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved add link to each image with jquery [closed] <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] This should do as you want: $(&#8220;div .copy-url&#8221;).each(function() { var imgval = $(this).find(&#8216;.copy-url&#8217;).val(); var sharer = &#8220;&lt;a class=&#8221;share&#8221; href=&#8221;&#8221;+imgval+&#8221;&#8221;&gt;share&lt;\/a&gt;&#8221;; $(this).append(sharer) }); You had the following mistakes: You had mismatching quotes in &#8220;&lt;a class=&#8221;share&#8221;&gt;&#8221; should be &#8220;&lt;a class=&#8221;share&#8221;&gt;&#8221; In the line $(&#8216;.copy-url&#8217;).val you are missing $(this).find and () after your .val. Should be $(this).find(&#8216;.copy-url&#8217;).val() You &#8230; <a title=\"[Solved] add link to each image with jquery [closed]\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/\" aria-label=\"More on [Solved] add link to each image with jquery [closed]\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[388],"class_list":["post-16137","post","type-post","status-publish","format-standard","hentry","category-solved","tag-jquery"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Solved] add link to each image with jquery [closed] - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] add link to each image with jquery [closed] - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] This should do as you want: $(&quot;div .copy-url&quot;).each(function() { var imgval = $(this).find(&#039;.copy-url&#039;).val(); var sharer = &quot;&lt;a class=&quot;share&quot; href=&quot;&quot;+imgval+&quot;&quot;&gt;share&lt;\/a&gt;&quot;; $(this).append(sharer) }); You had the following mistakes: You had mismatching quotes in &quot;&lt;a class=&quot;share&quot;&gt;&quot; should be &quot;&lt;a class=&quot;share&quot;&gt;&quot; In the line $(&#039;.copy-url&#039;).val you are missing $(this).find and () after your .val. Should be $(this).find(&#039;.copy-url&#039;).val() You ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-14T03:32:42+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-link-to-each-image-with-jquery-closed\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-link-to-each-image-with-jquery-closed\\\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] add link to each image with jquery [closed]\",\"datePublished\":\"2022-10-14T03:32:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-link-to-each-image-with-jquery-closed\\\/\"},\"wordCount\":60,\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"keywords\":[\"jquery\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-link-to-each-image-with-jquery-closed\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-link-to-each-image-with-jquery-closed\\\/\",\"name\":\"[Solved] add link to each image with jquery [closed] - JassWeb\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\"},\"datePublished\":\"2022-10-14T03:32:42+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-link-to-each-image-with-jquery-closed\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-link-to-each-image-with-jquery-closed\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/solved-add-link-to-each-image-with-jquery-closed\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] add link to each image with jquery [closed]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#website\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/wp-content\\\/uploads\\\/2021\\\/02\\\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/#\\\/schema\\\/person\\\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"contentUrl\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/wp-content\\\/litespeed\\\/avatar\\\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\\\/\\\/jassweb.com\"],\"url\":\"https:\\\/\\\/jassweb.com\\\/solved\\\/author\\\/jaspritsinghghumangmail-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] add link to each image with jquery [closed] - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] add link to each image with jquery [closed] - JassWeb","og_description":"[ad_1] This should do as you want: $(\"div .copy-url\").each(function() { var imgval = $(this).find('.copy-url').val(); var sharer = \"&lt;a class=\"share\" href=\"\"+imgval+\"\"&gt;share&lt;\/a&gt;\"; $(this).append(sharer) }); You had the following mistakes: You had mismatching quotes in \"&lt;a class=\"share\"&gt;\" should be \"&lt;a class=\"share\"&gt;\" In the line $('.copy-url').val you are missing $(this).find and () after your .val. Should be $(this).find('.copy-url').val() You ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/","og_site_name":"JassWeb","article_published_time":"2022-10-14T03:32:42+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] add link to each image with jquery [closed]","datePublished":"2022-10-14T03:32:42+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/"},"wordCount":60,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["jquery"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/","url":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/","name":"[Solved] add link to each image with jquery [closed] - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-14T03:32:42+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-add-link-to-each-image-with-jquery-closed\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] add link to each image with jquery [closed]"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1777008400","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/16137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=16137"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/16137\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=16137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=16137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=16137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}