Unable to change attr “href” at runtime-Collection of common programming errors
I’ve got a problem with a Kendo Mobile UI app (using Icenium).
I’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’s current status.
Here the html :
${data.mbLastName} ${data.mbFirstName}
And here the js :
(on the show method called by data-show) : [...] $('#attendance-'+idPresence).addClass(newClass); $('#attendance-'+idPresence).addClass("km-listview-link");
var query = "\\#attendances-view?status=switch&idPresence="+idPresence+"&etat="+newEtat;
$('#attendance-'+idPresence).attr("href", query);
[...]
The ‘query’ variable here is not really important, it doesn’t work whatever I give in, I could write “mickey mouse” it wouldn’t work. What’s strange is that the two “addClass” work well, but the .attr(…) seems to do absolutely nothing.
I’ve tried also with .prop(‘href’, 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’t get it. Is it simply overrode by the listview’s template (I wouldn’t see why, but still…) ?
Thanks in advance G.
Edit : as a complement, I do nothing in the beforeShow and the init events
Edit2 : found a workaround (right after posting… lol…)
I put a with the id around the :
${data.mbLastName} ${data.mbFirstName}
and changed a tad the js to actually work like that :
$('#attendance-'+idPresence+' a').addClass(newClass);
$('#attendance-'+idPresence+' a').addClass("km-listview-link");
var query = "\#attendances-view?status=switch&idPresence="+idPresence+"&etat="+newEtat;
$('#attendance-'+idPresence+' a').attr("href", query);
It works. But I’d be really happy if someone could tell me
1) if it’s a good idea to do things this way 2) why it didn’t work without the