jQuery

Having settled on jQuery for a front-end JavaScript library (although possibly YUI for admin interfaces), I’m just going to collect little snippets of wisdom.

Replace function

It seems like replace is the missing function, however, with jQuery syntax it’s easier than you might have thought:

$("#oldElement").after(newElement).remove(); 

And if you really want a replace function, this was suggested as a pluggin:

$.fn.replace = function(o) { return this.after(o).remove(); }; 

Last modified: April 18, 2007

Contribute to this article:

NB: Posting a comment means that you agree to the comments policy.

NB: Your email will not be shown, published or used.

Allowed HTML tags: a, acronym, strong, code, em, blockquote, ul, ol, li.