0

I'm trying to create a CSS class with the following:

var not_cursor = $('<style>#NOT_CURSOR { CURSOR: NONE; BACKGROUND: URL("images/NOT1.png") NO-REPEAT LEFT TOP; 
                  POSITION: ABSOLUTE;
                  DISPLAY: NONE;
                  TOP: 0;
                  LEFT: 0;
                  Z-INDEX: 10000;}</style>');
$('html > head').append(not_cursor); 

And then in another file I try accessing $('#NOT_CURSOR') but I get an error -

Uncaught SyntaxError: Unexpected token ILLEGAL 

And it's telling me this occurs on line 1. Any help?

Thanks.

1
  • Did you try $('head').append(not_cursor);? Also, the error is in line 1 because it comes from the element dynamically added to the DOM, not in the script. And also, are you trying to select a class #NOT_CURSOR with an ID selector $('#NOT_CURSOR')? Commented Jun 2, 2012 at 22:24

1 Answer 1

4

Try keeping it all on one line or concatening the separate line chunks.

jsFiddle example.

OR, use the multi-line escape trick: jsFiddle example.

var not_cursor = $('<style>#NOT_CURSOR { CURSOR: NONE; BACKGROUND: URL("images/NOT1.png") NO-REPEAT LEFT TOP; \
                  POSITION: ABSOLUTE; \
                  DISPLAY: NONE; \
                  TOP: 0; \
                  LEFT: 0; \
                  Z-INDEX: 10000;}</style>');
$('html > head').append(not_cursor); 

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.