Bug Tracker

Ticket #5316: jquery.txt

File jquery.txt, 861 bytes (added by TUSHKA, 10 years ago)

Possible Fix

Line 
1var jq = $("<selector1>") // selects more than one element
2jq.replaceAll("<selector2>")
3
4only the first matched element from jq will show up as the replacement for "<selector2>"
5
6Possible Fix:  See Attachment
7
8
9
10jQuery.each({
11        appendTo: "append",
12        prependTo: "prepend",
13        insertBefore: "before",
14        insertAfter: "after",
15        replaceAll: "replaceWith"
16}, function(name, original){
17        jQuery.fn[ name ] = function( selector ) {
18                var ret = [], insert = jQuery( selector );
19
20                for ( var i = 0, l = insert.length; i < l; i++ ) {
21                        var elems = (i > 0 ? this.clone(true) : this).get();
22                        //jQuery.fn[ original ].apply( jQuery(insert[i]), elems );      // this is wrong
23                        jQuery.fn[ original ].call( jQuery(insert[i]), elems ); // this is what it should be
24                        ret = ret.concat( elems );
25                }
26
27                return this.pushStack( ret, name, selector );
28        };
29});