1

I have an element like

<namespace:my_name>Some <b>html</b> here!</namespace:my_name>

How do I get the jQuery element? This doesnt work:

var el = $('namespace:my_name');
alert(el.length) // = 0
Xaver
  • 11,144
  • 13
  • 56
  • 91

3 Answers3

3

Escape the colon, it has a special meaning in CSS selectors

 $('namespace\\:my_name');
Prinzhorn
  • 22,120
  • 7
  • 61
  • 65
2

You have to escape :, so try this

 $("namespace\\:my_name")

From reference

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \.

Visit Selectors

Satpal
  • 132,252
  • 13
  • 159
  • 168
2

Check out the jQuery documentation for selectors. You must escape the selector with two backslashes like so:

$('namespace\\:my_name');

This is what is known as a literal. There are several other characters that can also be literals, they are:

!"#$%&'()*+,./:;<=>?@[\]^`{|}~
Matthew R.
  • 4,332
  • 1
  • 24
  • 39