- $(anchor).text(txt);
$(links).append($("<span>"+ pretxt + "</span>")).append(anchor);
works. this is the workaround code I ended up using.
The following only shows pretxt, seemingly losing the original anchor node:
- t = anchor;
- anchor = $("<span>"+ pretxt + "</span>").insertBefore(t);
- $(links).append(anchor);
(Using 'add' instead of 'insertBefore' in the above code procures the same result).
What have I not understood?
Also kinda irks me that the official jquery docs never tell me anything about the return values of functions, it just lists a cryptic 'jquery' as the return value for pretty much everything.
Another thing: is there a way to prepend text to an element without creating an element? The "span" is only there so that jquery lets me do it with a constructor.