Reputation: 837
Running Splunk examples and I get an error in this function.
var injectCode = function(code) {
var sTag = document.createElement("script");
sTag.type = "text/javascript";
sTag.text = code;
$(head).append(sTag);
return sTag;
}
The exact error is in $(head).append(sTag);
. This is placed inside a Jade file and it's running on Node. What am I doing wrong here?
EDIT - Sorry, head
is defined as var head = $("head");
right above the function.
And code
comes from this function
var getCode = function(id) {
var code = "";
$(id + " pre li").each(function(index, line) {
var lineCode = "";
$("span" ,line).each(function(index, span) {
if ($(span).hasClass("com")) {
lineCode += " ";
}
else {
lineCode += $(span).text();
}
});
lineCode += "\\n";
code += lineCode;
});
return code;
}
Upvotes: -1
Views: 2009
Reputation: 664538
Try to exchange lineCode += "\\n";
for
lineCode += "\n";
I assume you're dealing with a code string (to which you want to add a newline), not a string literal string (to which you want to add the \n
literal).
Upvotes: 1
Reputation: 74420
head is a tag, use that:
$('head').append(sTag);
EDIT:
I would say remove this:
lineCode += "\\n";
Upvotes: 3