2

This one works, actually:

$('.open-submenu > a').append("<span class='open-submenu-sym'>+</span>");

I would like to change the former to:

var open-string = "<span class='open-submenu-sym'>+</span>";
$('.open-submenu > a').append(open-string);

but it seems not working...I tried also $('.open-submenu > a').append('' + open-string); and $('.open-submenu > a').append("" + open-string); but still doesn't work...is it possible to accomplish that?

2 Answers2

3

The variable name is invalid since it includes - in your variable name. To make it valid replace the - character from the variable name.

var open_string = "<span class='open-submenu-sym'>+</span>";
$('.open-submenu > a').append(open_string);


For more info : What characters are valid for JavaScript variable names?

MDN Docs : Variables

Community
  • 1
  • 1
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
1

Your variable name is invalid because of the - character, which isn't allowed in JavaScript variable names.

Change to:

var openString = "<span class='open-submenu-sym'>+</span>";
$('.open-submenu > a').append(openString);

Remember to check the console for errors, because this will be producing an error which helps to find the problem:

Uncaught SyntaxError: Unexpected token -

MrCode
  • 63,975
  • 10
  • 90
  • 112