{"id":34188,"date":"2023-03-02T17:25:08","date_gmt":"2023-03-02T11:55:08","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/"},"modified":"2023-03-02T17:25:08","modified_gmt":"2023-03-02T11:55:08","slug":"solved-jquery-multiple-getelementbyid","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/","title":{"rendered":"[Solved] jQuery multiple getElementByID"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-38055553\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"38055553\" data-parentid=\"37683773\" 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>I think this will help you to achieve your goal. I have removed some unwanted details from your example, and try to keep it as simple as possible. <\/p>\n<pre><code>&lt;div class=\"action\" &gt;\n    &lt;span class=\"MyBtn\" rel=\"myModal1\" style=\"color:orange\"&gt;Title 1&lt;\/span&gt;\n&lt;\/div&gt; \n&lt;!-- The Modal 1 --&gt;\n&lt;div id='myModal1' class=\"modal\" style=\"display:none\"&gt;\n    &lt;!-- Modal content 1 --&gt;\n    &lt;div class=\"modal-content\"&gt;\n        &lt;div class=\"modal-header\"&gt;\n            &lt;span class=\"close\"  rel=\"myModal1\"  &gt;X&lt;\/span&gt;\n            &lt;h2 style=\"text-align:center\"&gt;Popup 1 header&lt;\/h2&gt;\n        &lt;\/div&gt;\n        &lt;div class=\"modal-body\"&gt;'Popup 1 content goes here...'&lt;\/div&gt;\n        &lt;div class=\"modal-footer\"&gt;&lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n\n\n\n&lt;div class=\"action\" &gt;\n    &lt;span class=\"MyBtn\" rel=\"myModal2\" style=\"color:orange\"&gt;Title 2&lt;\/span&gt;\n&lt;\/div&gt; \n&lt;!-- The Modal 2 --&gt;\n&lt;div id='myModal2' class=\"modal\" style=\"display:none\"&gt;\n    &lt;!-- Modal content 2--&gt;\n    &lt;div class=\"modal-content\"&gt;\n        &lt;div class=\"modal-header\"&gt;\n            &lt;span class=\"close\"  rel=\"myModal2\" &gt;X&lt;\/span&gt;\n            &lt;h2 style=\"text-align:center\"&gt;Popup 2 header&lt;\/h2&gt;\n        &lt;\/div&gt;\n        &lt;div class=\"modal-body\"&gt;'Popup 2 content goes here...'&lt;\/div&gt;\n        &lt;div class=\"modal-footer\"&gt;&lt;\/div&gt;\n    &lt;\/div&gt;\n&lt;\/div&gt;\n<\/code><\/pre>\n<p>The above html portion can be generated with the help of any looping structure. Please notice that I have write the id of the modal container in <i>rel<\/i> attribute at two different places.<\/p>\n<ol>\n<li>In the <i>span<\/i> tag with MyBtn class.<\/li>\n<li>In the <i>span<\/i> tag with close class.<\/li>\n<\/ol>\n<p>You need to generate the unique id for your modal cotainer and also should be written there. <em>(You can use $active_row-&gt;ID, insted of the serial number)<\/em><\/p>\n<p>Here is the script, which will open and close the modal box.<\/p>\n<pre><code>&lt;script type=\"text\/javascript\"&gt;\n    var button_click = function() {\n        var ModalID = this.getAttribute(\"rel\");\n        document.getElementById(ModalID).style.display = 'block';\n    };\n\n    var close_click = function() {\n        var ModalID = this.getAttribute(\"rel\");\n        document.getElementById(ModalID).style.display = 'none';\n    };\n\n\n    \/\/ Get the button that opens the modal\n    var btn = document.getElementsByClassName('MyBtn');\n\n    \/\/ Get the &lt;span&gt; element that closes the modal\n    var close = document.getElementsByClassName('close') ;\n\n    \/\/ Assign the events to the buttons (open &amp; close)\n    for(iCount = 0; iCount &lt; btn.length; iCount++) {\n        btn[iCount].addEventListener('click', button_click, false) ;\n        close[iCount].addEventListener('click', close_click, false) ;\n    }\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>I wish it will help enough. <\/p>\n<p>Have a great time.<\/p>\n<\/p><\/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 jQuery multiple getElementByID <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] I think this will help you to achieve your goal. I have removed some unwanted details from your example, and try to keep it as simple as possible. &lt;div class=&#8221;action&#8221; &gt; &lt;span class=&#8221;MyBtn&#8221; rel=&#8221;myModal1&#8243; style=&#8221;color:orange&#8221;&gt;Title 1&lt;\/span&gt; &lt;\/div&gt; &lt;!&#8211; The Modal 1 &#8211;&gt; &lt;div id=&#8217;myModal1&#8242; class=&#8221;modal&#8221; style=&#8221;display:none&#8221;&gt; &lt;!&#8211; Modal content 1 &#8211;&gt; &lt;div class=&#8221;modal-content&#8221;&gt; &lt;div &#8230; <a title=\"[Solved] jQuery multiple getElementByID\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/\" aria-label=\"More on [Solved] jQuery multiple getElementByID\">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":[790,333,388,339],"class_list":["post-34188","post","type-post","status-publish","format-standard","hentry","category-solved","tag-foreach","tag-javascript","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] jQuery multiple getElementByID - 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-jquery-multiple-getelementbyid\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] jQuery multiple getElementByID - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] I think this will help you to achieve your goal. I have removed some unwanted details from your example, and try to keep it as simple as possible. &lt;div class=&quot;action&quot; &gt; &lt;span class=&quot;MyBtn&quot; rel=&quot;myModal1&quot; style=&quot;color:orange&quot;&gt;Title 1&lt;\/span&gt; &lt;\/div&gt; &lt;!-- The Modal 1 --&gt; &lt;div id=&#039;myModal1&#039; class=&quot;modal&quot; style=&quot;display:none&quot;&gt; &lt;!-- Modal content 1 --&gt; &lt;div class=&quot;modal-content&quot;&gt; &lt;div ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-02T11:55:08+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-jquery-multiple-getelementbyid\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] jQuery multiple getElementByID\",\"datePublished\":\"2023-03-02T11:55:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/\"},\"wordCount\":136,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"foreach\",\"javascript\",\"jquery\",\"php\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/\",\"name\":\"[Solved] jQuery multiple getElementByID - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2023-03-02T11:55:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] jQuery multiple getElementByID\"}]},{\"@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=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] jQuery multiple getElementByID - 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-jquery-multiple-getelementbyid\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] jQuery multiple getElementByID - JassWeb","og_description":"[ad_1] I think this will help you to achieve your goal. I have removed some unwanted details from your example, and try to keep it as simple as possible. &lt;div class=\"action\" &gt; &lt;span class=\"MyBtn\" rel=\"myModal1\" style=\"color:orange\"&gt;Title 1&lt;\/span&gt; &lt;\/div&gt; &lt;!-- The Modal 1 --&gt; &lt;div id='myModal1' class=\"modal\" style=\"display:none\"&gt; &lt;!-- Modal content 1 --&gt; &lt;div class=\"modal-content\"&gt; &lt;div ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/","og_site_name":"JassWeb","article_published_time":"2023-03-02T11:55:08+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-jquery-multiple-getelementbyid\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] jQuery multiple getElementByID","datePublished":"2023-03-02T11:55:08+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/"},"wordCount":136,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["foreach","javascript","jquery","php"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/","url":"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/","name":"[Solved] jQuery multiple getElementByID - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2023-03-02T11:55:08+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-jquery-multiple-getelementbyid\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] jQuery multiple getElementByID"}]},{"@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=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","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\/34188","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=34188"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/34188\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=34188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=34188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=34188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}