Abstracting a jQuery selection / making it more flexible
Hello all,
please consider the following code, which works fine:
- function loadElements($t) { //load target selection into DOM
- if ($.cache()) $t.each(function() { //iterate through elements
- _ld($(this), $.cache().find("#" + $(this).attr("id"))); //load target element into DOM
- });
- }
- function _ld ($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 element into primary DOM
- }
I would like to abstract this bit:
- _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? :
- _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!