{"id":32767,"date":"2023-02-01T16:26:01","date_gmt":"2023-02-01T10:56:01","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/"},"modified":"2023-02-01T16:26:01","modified_gmt":"2023-02-01T10:56:01","slug":"solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/","title":{"rendered":"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate?"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-19226755\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"19226755\" data-parentid=\"19226585\" data-score=\"0\" 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>You can do it like Braziliam way, we call it as &#8220;Gambiarra&#8221;<\/p>\n<pre><code>$('input [type=submit]').click(function(){\n   var productname = $(this).parent().find('.post-meta-ab a').html();\n});\n<\/code><\/pre>\n<p>PS. If you cant set a UNIQUE ID for your DOM elements, don&#8217;t use any at all.<\/p>\n<p>Basically for each product on you list you have this structure:<\/p>\n<pre><code>&lt;li class=\"ms-tt grid_3\" data-id=\"id-1\" data-type=\"digital\"&gt;\n                        &lt;div class=\"m-thumb entry-image hover-content\"&gt;\n                            &lt;a href=\"#\"&gt;&lt;img src=\"images\/jewellery-tools\/casting-soldering1\/14.jpg\" alt=\"Flasks Stainless Steel Perforated C-16\"&gt;&lt;\/a&gt;\n                            &lt;div class=\"image-overlay\"&gt;\n                                &lt;div class=\"buttons-tt clearfix\"&gt;\n                                    &lt;a class=\"permalink\" href=\"#\"&gt;&lt;i class=\"icon-link\"&gt;&lt;\/i&gt;&lt;\/a&gt;\n                                    &lt;a class=\"zoom\" href=\"images\/jewellery-tools\/casting-soldering1\/14.jpg\" data-gal=\"photo[portfolio]\" title=\"Flasks Stainless Steel Perforated C-16\"&gt;&lt;i class=\"icon-resize-full\"&gt;&lt;\/i&gt;&lt;\/a&gt;\n                                &lt;\/div&gt;\n                            &lt;\/div&gt;\n                        &lt;\/div&gt;\n                        &lt;p class=\"post-meta-ab\"&gt;&lt;span&gt;&lt;a href=\"#\"&gt;Flasks Stainless Steel Perforated C-16&lt;\/a&gt;&lt;\/span&gt;&lt;br \/&gt;\n                        &lt;span&gt;Details: Flasks Stainless Steel Perforated For Casting 3\" Dia X 5\",6\" &amp; 7\"&lt;\/span&gt;&lt;br \/&gt;\n                        &lt;span&gt;&lt;i class=\"icon-circle\"&gt;&lt;\/i&gt;Shipping Weight: 750gms&lt;\/span&gt;&lt;br \/&gt;&lt;span&gt;&lt;i class=\"icon-circle\"&gt;&lt;\/i&gt;Price: &amp;#8364; 17.00&lt;\/span&gt;&lt;br \/&gt;\n                        &lt;span&gt;&lt;i class=\"icon-circle\"&gt;&lt;\/i&gt;Quantity: &lt;input type=\"text\" style=\"width:20px\" maxlength=\"100\" name=\"a1\" id=\"a1\" \/&gt;\n                        &lt;input type=\"submit\" value=\"Add\" style=\"margin-top:-8px\" class=\"btn btn-danger\" name=\"asubmit\" id=\"a1sub\" \/&gt;&lt;\/span&gt;&lt;\/p&gt;\n                    &lt;\/li&gt;\n<\/code><\/pre>\n<p>Inside your <code>&lt;li&gt;<\/code> element you have your button and you have a <code>&lt;p&gt;<\/code> with your product title, and you <code>&lt;p&gt;<\/code> have a &#8220;post-meta-ab&#8221; class.<br \/>\nSo when you say:<\/p>\n<pre><code>$('input [type=submit]').click(function(){ \/\/here you'r saying, \"when any input submit get clicked execute the code above\"\n   var productname = $(this).parent().find('.post-meta-ab a').html(); \/\/ here you are saying, $(this) means the input submit clicked, and parent() means your &lt;li&gt;, and finally you tell to look for any element with the post-meta-ab class and look for the a inside it.\n});\n<\/code><\/pre>\n<p>Understand now?<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">8<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Hundreds of buttons in one page with same name and same ids, how to differentiate? <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] You can do it like Braziliam way, we call it as &#8220;Gambiarra&#8221; $(&#8216;input [type=submit]&#8217;).click(function(){ var productname = $(this).parent().find(&#8216;.post-meta-ab a&#8217;).html(); }); PS. If you cant set a UNIQUE ID for your DOM elements, don&#8217;t use any at all. Basically for each product on you list you have this structure: &lt;li class=&#8221;ms-tt grid_3&#8243; data-id=&#8221;id-1&#8243; data-type=&#8221;digital&#8221;&gt; &lt;div &#8230; <a title=\"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/\" aria-label=\"More on [Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate?\">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":[954,346,388,339],"class_list":["post-32767","post","type-post","status-publish","format-standard","hentry","category-solved","tag-button","tag-html","tag-jquery","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate? - 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-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] You can do it like Braziliam way, we call it as &#8220;Gambiarra&#8221; $(&#039;input [type=submit]&#039;).click(function(){ var productname = $(this).parent().find(&#039;.post-meta-ab a&#039;).html(); }); PS. If you cant set a UNIQUE ID for your DOM elements, don&#8217;t use any at all. Basically for each product on you list you have this structure: &lt;li class=&quot;ms-tt grid_3&quot; data-id=&quot;id-1&quot; data-type=&quot;digital&quot;&gt; &lt;div ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-01T10:56:01+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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate?\",\"datePublished\":\"2023-02-01T10:56:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/\"},\"wordCount\":102,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"button\",\"html\",\"jquery\",\"php\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/\",\"name\":\"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2023-02-01T10:56:01+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate?\"}]},{\"@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\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate? - 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-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate? - JassWeb","og_description":"[ad_1] You can do it like Braziliam way, we call it as &#8220;Gambiarra&#8221; $('input [type=submit]').click(function(){ var productname = $(this).parent().find('.post-meta-ab a').html(); }); PS. If you cant set a UNIQUE ID for your DOM elements, don&#8217;t use any at all. Basically for each product on you list you have this structure: &lt;li class=\"ms-tt grid_3\" data-id=\"id-1\" data-type=\"digital\"&gt; &lt;div ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/","og_site_name":"JassWeb","article_published_time":"2023-02-01T10:56:01+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate?","datePublished":"2023-02-01T10:56:01+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/"},"wordCount":102,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["button","html","jquery","php"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/","url":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/","name":"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-02-01T10:56:01+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-hundreds-of-buttons-in-one-page-with-same-name-and-same-ids-how-to-differentiate\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Hundreds of buttons in one page with same name and same ids, how to differentiate?"}]},{"@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\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","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\/32767","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=32767"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/32767\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=32767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=32767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=32767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}