Wednesday 15 September 2010

swap - One-line jQuery innerHtml swapper -


Since we can not do some $ ('el1') Swap ('el2') with pure jQuery (anyway?), If you have enough creativity to turn it on, then I ask you partner comers

  var temp = $ ('El1'). Html (); . $ ('EL1') HTML (. $ ('El2') HTML); $ ('El2') HTML (floating).   

In one-liner.

(I have tried several ideas myself, which use the toggle , but the way the HTML content increases to compensate However ... Twas became fun.)

code more To make the readable, suppose that the two containers have jquery objects a and B .

is displayed by:

Pre> A Viperiner ('

) AppendTo (B) .contents (.) Opening () .interview () (appendTo (''. '' End (). The end () appears (".b"). Content (). Opening ();

... which is a completely monstrous one-liner But this was asked!

> Even better, it simplifies the following:

  A.wrapInner ('& quot; div class = "a" />;). Attachments (b.contents ()) .. a) AppendTo (b) .contents () open ();   

... which is a less monstrous one-liner!

Confirm .html () at any point, which will deny you the chance of chaining more jQuery method.

No comments:

Post a Comment