{"id":17014,"date":"2022-10-22T20:44:41","date_gmt":"2022-10-22T15:14:41","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/"},"modified":"2022-10-22T20:44:41","modified_gmt":"2022-10-22T15:14:41","slug":"solved-javascript-and-jquery-alert-findtdfirst-html-and-click","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/","title":{"rendered":"[Solved] JavaScript and jQuery Alert find(&#8220;td:first&#8221;).html() and Click"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-55408743\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"55408743\" data-parentid=\"55407451\" 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>It&#8217;s really unclear what the goal is here. Maybe this will help, consider the following code.<\/p>\n<\/p>\n<div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"true\" data-babel=\"false\">\n<div class=\"snippet-code\">\n<pre class=\"snippet-code-js lang-js prettyprint-override\"><code>$(function() {\r\n  function cereal(id, name, like) {\r\n    this.id = id;\r\n    this.name = name;\r\n    this.like = like;\r\n  }\r\n\r\n  const cereals = [\r\n    new cereal(1, 'Captain Crunch', 'Yes'),\r\n    new cereal(2, 'Frosted Wheats ', 'Yes'),\r\n    new cereal(3, 'Shredded Wheat', 'No'),\r\n    new cereal(4, 'Trix', 'No'),\r\n    new cereal(5, 'Count Chocula', 'No'),\r\n  ];\r\n\r\n  var output = \"&lt;h1&gt;Cereal Listing&lt;\/h1&gt;\";\r\n  output += \"&lt;table class=\"cereal-table\"&gt;&lt;thead&gt;\";\r\n  output += \"&lt;tr&gt;&lt;th&gt;Id&lt;\/th&gt;&lt;th&gt;Cereal Name&lt;\/th&gt;&lt;th&gt;Like?&lt;\/th&gt;&lt;\/tr&gt;\";\r\n  output += \"&lt;\/thead&gt;&lt;tbody&gt;\";\r\n  $.each(cereals, function(k, c) {\r\n    var row = $(\"&lt;tr&gt;\", {\r\n      \"data-c-id\": k\r\n    });\r\n    $(\"&lt;td&gt;\").html(c.id).appendTo(row);\r\n    $(\"&lt;td&gt;\").html(c.name).appendTo(row);\r\n    $(\"&lt;td&gt;\").html(c.like).appendTo(row);\r\n    output += row.prop(\"outerHTML\");\r\n  });\r\n  output += \"&lt;\/tbody&gt;&lt;\/table&gt;\";\r\n\r\n  $(\"#cer\").html(output);\r\n  $(\".cereal-table\").on(\"click\", \"tr\", function(e) {\r\n    var cId = parseInt($(this).data(\"c-id\"));\r\n    console.log(\"Row C-ID: \" + cId);\r\n    var data = \"\";\r\n    data += \"ID: \" + cereals[cId].id;\r\n    data += \", Name: \" + cereals[cId].name;\r\n    data += \", Like: \" + cereals[cId].like\r\n    alert(data);\r\n  });\r\n});<\/code><\/pre>\n<pre class=\"snippet-code-html lang-html prettyprint-override\"><code>&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/jquery\/3.3.1\/jquery.min.js\"&gt;&lt;\/script&gt;\r\n&lt;div id=\"cer\"&gt;&lt;\/div&gt;<\/code><\/pre>\n<\/div>\n<\/div>\n<p>Since jQuery is a JavaScript Framework, you can mix and match both, yet I try to remain in one or the other. This is all in jQuery.<\/p>\n<p>The function creates an Object. You have 5 objects in an Array and we&#8217;re going to iterate the Array using <code>$.each()<\/code>. This is a functioned designed for this. See:<br \/>\n<a rel=\"nofollow noopener\" target=\"_blank\" href=\"http:\/\/api.jquery.com\/jquery.each\/\">jQuery.each()<\/a><\/p>\n<p>Each Object has parameters we can call and insert into the Table Cell elements <code>&lt;td&gt;<\/code>. jQuery give us the ability to quickly create elements as jQuery Objects: <code>$(\"&lt;td&gt;\")<\/code>.<\/p>\n<p>Since the goal appears to be to create an <code>output<\/code> string of HTML text, we can convert all the jQuery Objects we&#8217;ve create into HTML by asking for the <code>outerHTML<\/code> property.<\/p>\n<p>The result of running the code is:<\/p>\n<pre><code>&lt;h1&gt;Cereal Listing&lt;\/h1&gt;&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Id&lt;\/th&gt;&lt;th&gt;Cereal Name&lt;\/th&gt;&lt;th&gt;Like?&lt;\/th&gt;&lt;\/tr&gt;&lt;\/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;1&lt;\/td&gt;&lt;td&gt;Captain Crunch&lt;\/td&gt;&lt;td&gt;Yes&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&lt;td&gt;2&lt;\/td&gt;&lt;td&gt;Frosted Wheats &lt;\/td&gt;&lt;td&gt;Yes&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&lt;td&gt;3&lt;\/td&gt;&lt;td&gt;Shredded Wheat&lt;\/td&gt;&lt;td&gt;No&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&lt;td&gt;4&lt;\/td&gt;&lt;td&gt;Trix&lt;\/td&gt;&lt;td&gt;No&lt;\/td&gt;&lt;\/tr&gt;&lt;tr&gt;&lt;td&gt;5&lt;\/td&gt;&lt;td&gt;Count Chocula&lt;\/td&gt;&lt;td&gt;No&lt;\/td&gt;&lt;\/tr&gt;&lt;\/tbody&gt;&lt;\/table&gt;\n<\/code><\/pre>\n<p>Once the table is constructed and outputted, you can bind a <code>click<\/code> event to the Row with <code>.on()<\/code> or <code>.click()<\/code>. I advise the <code>.on()<\/code> since it more tolerate of dynamic content.<\/p>\n<p>We bind the <code>click<\/code> event to each row and then collect the data from the row and create an alert.<\/p>\n<p>Hope this helps.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">4<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved JavaScript and jQuery Alert find(&#8220;td:first&#8221;).html() and Click <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] It&#8217;s really unclear what the goal is here. Maybe this will help, consider the following code. $(function() { function cereal(id, name, like) { this.id = id; this.name = name; this.like = like; } const cereals = [ new cereal(1, &#8216;Captain Crunch&#8217;, &#8216;Yes&#8217;), new cereal(2, &#8216;Frosted Wheats &#8216;, &#8216;Yes&#8217;), new cereal(3, &#8216;Shredded Wheat&#8217;, &#8216;No&#8217;), new &#8230; <a title=\"[Solved] JavaScript and jQuery Alert find(&#8220;td:first&#8221;).html() and Click\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/\" aria-label=\"More on [Solved] JavaScript and jQuery Alert find(&#8220;td:first&#8221;).html() and Click\">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":[1633,346,333,388],"class_list":["post-17014","post","type-post","status-publish","format-standard","hentry","category-solved","tag-alert","tag-html","tag-javascript","tag-jquery"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] JavaScript and jQuery Alert find(&quot;td:first&quot;).html() and Click - 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-javascript-and-jquery-alert-findtdfirst-html-and-click\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] JavaScript and jQuery Alert find(&quot;td:first&quot;).html() and Click - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] It&#8217;s really unclear what the goal is here. Maybe this will help, consider the following code. $(function() { function cereal(id, name, like) { this.id = id; this.name = name; this.like = like; } const cereals = [ new cereal(1, &#039;Captain Crunch&#039;, &#039;Yes&#039;), new cereal(2, &#039;Frosted Wheats &#039;, &#039;Yes&#039;), new cereal(3, &#039;Shredded Wheat&#039;, &#039;No&#039;), new ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-22T15:14:41+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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] JavaScript and jQuery Alert find(&#8220;td:first&#8221;).html() and Click\",\"datePublished\":\"2022-10-22T15:14:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/\"},\"wordCount\":210,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"alert\",\"html\",\"javascript\",\"jquery\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/\",\"name\":\"[Solved] JavaScript and jQuery Alert find(\\\"td:first\\\").html() and Click - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-22T15:14:41+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] JavaScript and jQuery Alert find(&#8220;td:first&#8221;).html() and Click\"}]},{\"@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] JavaScript and jQuery Alert find(\"td:first\").html() and Click - 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-javascript-and-jquery-alert-findtdfirst-html-and-click\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] JavaScript and jQuery Alert find(\"td:first\").html() and Click - JassWeb","og_description":"[ad_1] It&#8217;s really unclear what the goal is here. Maybe this will help, consider the following code. $(function() { function cereal(id, name, like) { this.id = id; this.name = name; this.like = like; } const cereals = [ new cereal(1, 'Captain Crunch', 'Yes'), new cereal(2, 'Frosted Wheats ', 'Yes'), new cereal(3, 'Shredded Wheat', 'No'), new ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/","og_site_name":"JassWeb","article_published_time":"2022-10-22T15:14:41+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] JavaScript and jQuery Alert find(&#8220;td:first&#8221;).html() and Click","datePublished":"2022-10-22T15:14:41+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/"},"wordCount":210,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["alert","html","javascript","jquery"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/","url":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/","name":"[Solved] JavaScript and jQuery Alert find(\"td:first\").html() and Click - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-22T15:14:41+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-javascript-and-jquery-alert-findtdfirst-html-and-click\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] JavaScript and jQuery Alert find(&#8220;td:first&#8221;).html() and Click"}]},{"@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\/17014","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=17014"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/17014\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=17014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=17014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=17014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}