{"id":492,"date":"2022-06-09T15:25:59","date_gmt":"2022-06-09T13:25:59","guid":{"rendered":"https:\/\/www.areaweb.sk\/?p=492"},"modified":"2022-06-09T15:26:00","modified_gmt":"2022-06-09T13:26:00","slug":"zoradenie-elementov-v-javascripte-sort-function","status":"publish","type":"post","link":"https:\/\/www.areaweb.sk\/cs\/zoradenie-elementov-v-javascripte-sort-function\/","title":{"rendered":"Zoradenie elementov v JavaScripte \/ sort function"},"content":{"rendered":"<pre class=\"wp-block-code\"><code>&lt;div class=&quot;produkt&quot;&gt;2&lt;\/div&gt;\n&lt;div class=&quot;produkt&quot;&gt;1&lt;\/div&gt;\n&lt;div class=&quot;produkt&quot;&gt;3&lt;\/div&gt;\n&lt;button id=&quot;zorad&quot;&gt;Zora\u010f&lt;\/button&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>  function zoradProdukty() {\n           var items = document.querySelectorAll('.produkt');   \/\/ definuj elementy\n           \/\/ magically coerce into an array first\n           items = Array.prototype.slice.call(items);\n           \/\/ Now we can sort it.  Sort alphabetically\n           items.sort(function(a, b){\n               return b.textContent.localeCompare(a.textContent);   \/\/ vymenit a b pre opacne zoradenie\n           });\n           \/\/ reatach the sorted elements\n           for(var i = 0, len = items.length; i &lt; len; i++) {\n               \/\/ store the parent node so we can reatach the item\n               var parent = items&#91;i].parentNode;\n               \/\/ detach it from wherever it is in the DOM\n               var detatchedItem = parent.removeChild(items&#91;i]);\n               parent.appendChild(detatchedItem);\n           }\n           window.scrollTo(0, 0);\n        }\n   document.getElementById('zorad').addEventListener('click', zoradProdukty)<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<div class=\"produkt\">2<\/div>\n<div class=\"produkt\">1<\/div>\n<div class=\"produkt\">3<\/div>\n<p> <button id=\"zorad\">Zora\u010f<\/button> function zoradProdukty() { var items = document.querySelectorAll(&#8218;.produkt&#8216;); \/\/ definuj elementy\u2026<\/p>","protected":false},"author":1,"featured_media":389,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[],"class_list":["post-492","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-js"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts\/492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/comments?post=492"}],"version-history":[{"count":0,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/posts\/492\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/media\/389"}],"wp:attachment":[{"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/media?parent=492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/categories?post=492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.areaweb.sk\/cs\/wp-json\/wp\/v2\/tags?post=492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}