Abstracting a jQuery selection / making it more flexible

Abstracting a jQuery selection / making it more flexible

Hello all,

please consider the following code, which works fine:

  1.    function loadElements($t) { //load target selection into DOM
  2.         if ($.cache()) $t.each(function() { //iterate through elements
  3.             _ld($(this), $.cache().find("#" + $(this).attr("id"))); //load target element into DOM
  4.         });
  5.     }

  6.    function _ld ($t, $h) { //load HTML of target selection into DOM
  7.         var $c = $h.clone();
  8.         $c.find("script").remove(); //prevent double firing of scripts
  9.         $t.html($c.html()); //inject element into primary DOM
  10.     }

I would like to abstract this bit:

  1. _ld($(this), $.cache().find("#" + $(this).attr("id"))); //load target element into DOM

...to copy any elements, not just those with an ID over to the target page

Just a guess - does this make any sense? :

  1. _ld($(this), $.cache().find($(this))); //load target element into DOM

Just tested the latter approach - does not work at all...


Any other ideas?
Thanks in advance!

jQuery Ajaxify Plugin: https://4nf.org/