-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.htmlFromScript.js
46 lines (39 loc) · 1.08 KB
/
jquery.htmlFromScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function getHtmlFromScript($context) {
if (typeof $context == 'undefined') {
$context = $('script[type="text/html"]');
}
else {
if (typeof $context == 'string') {
$context = $($context);
}
if (!$context.is('script')) {
$context = $context.find('script[type="text/html"]');
}
}
var text = '';
$context.each(function() {
text += $.trim($(this).html()).replace("//<![CDATA[", "").replace("//]]>", "").replace("<![CDATA[", "").replace("]]>", "");
});
var elements = $.parseHTML(text);
return elements;
}
$.fn.htmlFromScript = function($context) {
$(this).html(getHtmlFromScript($context));
return this;
};
$.fn.appendFromScript = function($context) {
$(this).append(getHtmlFromScript($context));
return this;
};
$.fn.prependFromScript = function($context) {
$(this).prepend(getHtmlFromScript($context));
return this;
};
$.fn.afterFromScript = function($context) {
$(this).after(getHtmlFromScript($context));
return this;
};
$.fn.beforeFromScript = function($context) {
$(this).before(getHtmlFromScript($context));
return this;
};