{"id":2503,"date":"2022-08-30T15:25:24","date_gmt":"2022-08-30T15:25:24","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/27\/unable-to-change-attr-href-at-runtime-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:25:24","modified_gmt":"2022-08-30T15:25:24","slug":"unable-to-change-attr-href-at-runtime-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/unable-to-change-attr-href-at-runtime-collection-of-common-programming-errors\/","title":{"rendered":"Unable to change attr &ldquo;href&rdquo; at runtime-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;ve got a problem with a Kendo Mobile UI app (using Icenium).<\/p>\n<p>I&#8217;m using a list view, and I want to change the url at runtime. The idea behind is that : everytime the user clicks on an item, it changes the color of the item via a dynamic change of the css class. I must also change the internal url the item points to, to reflect it&#8217;s current status.<\/p>\n<p>Here the html :<\/p>\n<pre><code>\n\n    <\/code><\/pre>\n<h3 data-bind=\"text: info\"><\/h3>\n<pre>\n    <\/pre>\n<ul id=\"attendances-data\"><\/ul>\n<pre>           \n\n\n\n \n${data.mbLastName} ${data.mbFirstName}           \n\n<\/pre>\n<p><code>And here the js :<\/code><\/p>\n<p><code>(on the show method called by data-show) : [...] $('#attendance-'+idPresence).addClass(newClass); $('#attendance-'+idPresence).addClass(\"km-listview-link\");<\/code><\/p>\n<pre><code><code> var query = \"\\\\#attendances-view?status=switch&amp;idPresence=\"+idPresence+\"&amp;etat=\"+newEtat;\n\n $('#attendance-'+idPresence).attr(\"href\", query);\n [...]\n<\/code><\/code><\/pre>\n<p>The &#8216;query&#8217; variable here is not really important, it doesn&#8217;t work whatever I give in, I could write &#8220;mickey mouse&#8221; it wouldn&#8217;t work. What&#8217;s strange is that the two &#8220;addClass&#8221; work well, but the .attr(&#8230;) seems to do absolutely nothing.<\/p>\n<p>I&#8217;ve tried also with .prop(&#8216;href&#8217;, query), with .attr({href: query,}), to no avail. The dynamically created ID works fine, as the selector works fine when doing the two addClass, so I really don&#8217;t get it. Is it simply overrode by the listview&#8217;s template (I wouldn&#8217;t see why, but still&#8230;) ?<\/p>\n<p>Thanks in advance G.<\/p>\n<p>Edit : as a complement, I do nothing in the beforeShow and the init events<\/p>\n<p>Edit2 : found a workaround (right after posting&#8230; lol&#8230;)<\/p>\n<p>I put a with the id around the :<\/p>\n<pre><code>${data.mbLastName} ${data.mbFirstName}  \n<\/code><\/pre>\n<p>and changed a tad the js to actually work like that :<\/p>\n<pre><code>$('#attendance-'+idPresence+' a').addClass(newClass);\n$('#attendance-'+idPresence+' a').addClass(\"km-listview-link\");\n\nvar query = \"\\#attendances-view?status=switch&amp;idPresence=\"+idPresence+\"&amp;etat=\"+newEtat;\n\n$('#attendance-'+idPresence+' a').attr(\"href\", query);\n<\/code><\/pre>\n<p>It works. But I&#8217;d be really happy if someone could tell me<\/p>\n<p>1) if it&#8217;s a good idea to do things this way 2) why it didn&#8217;t work without the<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-27 08:40:04. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve got a problem with a Kendo Mobile UI app (using Icenium). I&#8217;m using a list view, and I want to change the url at runtime. The idea behind is that : everytime the user clicks on an item, it changes the color of the item via a dynamic change of the css class. I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2503","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2503"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2503\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}