arvgta/ajaxify

Replace jQuery html() with replaceWith()

Closed this issue · 1 comments

I would like to move from using jQuery html() like this (in the last row):

    lDivs: function ($t) { //load target selections into DOM
        if ($.cache1()) $t.each(function() { //iterate through elements
            _ld($(this), $.cache1().find("#" + $(this).attr("id"))); //load target element into DOM
        });
    },

    ld: function ($t, $h) { //load HTML of target selection into DOM
        var $c = $h.clone();
        $c.find("script").remove(); //prevent double firing of scripts
        $t.html($c.html()); //inject div into primary DOM
    },

...which works well with jQuery replaceWith() like this (in the last row) :

    lDivs: function ($t) { //load target selections into DOM
        if ($.cache1()) $t.each(function() { //iterate through elements
            _ld($(this), $.cache1().find("#" + $(this).attr("id"))); //load target element into DOM
        });
    },

    ld: function ($t, $h) { //load HTML of target selection into DOM
        $t.replaceWith($h.clone().find("script").remove().end()); //inject div into primary DOM
    }

...which does not work from the second swap of content onwards.

Presumably not feasible

  • The main content div gets corrupted ($t in the above code)

Thus closing...