1

I have a unique situation where a dynamically driven link contains a type of ID I'm not able to target and hide with jquery. I'm calling it a pseudo ID, since it reminds me of pseudo classes, but I don't even think this type of ID exists.

Do you have a solution how I can target this link and hide it with this ID? I'm not able to physically change the ID, so I'm stuck hoping there was a way to get at it with jquery.

Here is the HTML with the ID in question:

<a href="http://www.helloworld.com" id="msgForum:print">test</a>

I tried removing it with an easy hide function, but I'm not able to target it, because of the :print that is present.

$('#msgForum:print').hide();

Here is my fiddle: http://jsfiddle.net/YAMVA/1/

Evan
  • 3,411
  • 7
  • 36
  • 53

3 Answers3

4

You just need to escape the special character : in the selector with double backslashes.

$('#msgForum\\:print').hide();

http://jsfiddle.net/jqHES/

from the jQuery Selectors documentation

To use any of the meta-characters ( such as  !"#$%&'()*+,./:;?@[\]^`{|}~ ) as a literal part of
a name, it must be escaped with with two backslashes: \\. For example, an element with id="foo.bar", 
can use the selector $("#foo\\.bar"). 
wirey00
  • 33,517
  • 7
  • 54
  • 65
4

use \\ to escape any special characters.

$('#msgForum\\:print').hide();

http://jsfiddle.net/YAMVA/3/

Specials characters : !"#$%&'()*+,./:;?@[\]^{|}~

Utopik
  • 3,783
  • 1
  • 21
  • 24
  • thank you for this lesson! and for the quick response! i wish I could give the feedback to everyone! – Evan Jun 24 '13 at 13:47
1

You could take advantage of id attribute selector:

DEMO

$('[id="msgForum:print"]').hide();
A. Wolff
  • 74,033
  • 9
  • 94
  • 155