-1

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; } 
10
  • 1
    What is head? Is it defined before? Commented Jul 3, 2013 at 14:20
  • 1
    Are you sure head exists? Maybe it should be document.head? Commented Jul 3, 2013 at 14:20
  • What are you getting the error from? Commented Jul 3, 2013 at 14:22
  • 1
    Shouldn't there be quotes around head, like $("head").append(sTag); Commented Jul 3, 2013 at 14:22
  • 1
    What is this text property you're setting? Commented Jul 3, 2013 at 14:22

2 Answers 2

3

head is a tag, use that:

$('head').append(sTag); 

EDIT:

I would say remove this:

lineCode += "\\n"; 
Sign up to request clarification or add additional context in comments.

2 Comments

This is placed inside a Jade file and it's running on Node. - is there something in Node/Jade that defines head that would let this work before your change? And you wouldn't get the exception that the OP is reporting if you used $(head) and head wasn't defined
@Ian ya true but i don't know what kind of error OP is talking about. Oops sorry, Ian, i saw the title now... Unexpected token ILLEGAL in jQuery
1

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).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.