1

I'm using jQuery with SharePoint 2013, and have to get the table Id to add an attribute. The table Id is

{44C80A95-F3E4-40DA-9A97-50CADFFFED61}-{DD02CEA7-CC2B-4E4A-A725-86E82C6D11FC}

When I use:

jQuery("#{44C80A95-F3E4-40DA-9A97-50CADFFFED61}-{DD02CEA7-CC2B-4E4A-A725-86E82C6D11FC}").attr("width","100%");

It gives me this erro:

Uncaught Error: Syntax error, unrecognized expression: #{44C80A95-F3E4-40DA-9A97-50CADFFFED61}-{DD02CEA7-CC2B-4E4A-A725-86E82C6D11FC} 

The problem is with the "{".

How to solve this problem?

Marc B
  • 348,685
  • 41
  • 398
  • 480
  • welp, 2 peeps already beat me to the answer, but they're spot on. This is just one more reason I ***HATE*** Sharepoint and will **NEVER** take a contract using it EVER again! You can check my blog for one of the craziest issues I ever saw -> http://spyk3lc.blogspot.com/2012/11/how-to-reset-digital-signature-on.html – SpYk3HH Jun 18 '14 at 14:23

2 Answers2

3

As per docs

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

You need to escape special character in selector or use name value attribute instead:

 jQuery("[id='{44C80A95-F3E4-40DA-9A97-50CADFFFED61}-{DD02CEA7-CC2B-4E4A-A725-86E82C6D11FC}']").attr("width","100%");
Milind Anantwar
  • 79,642
  • 23
  • 92
  • 120
1

By escaping the brackets ?

jQuery("#\{44C80A95-F3E4-40DA-9A97-50CADFFFED61\}-\{DD02CEA7-CC2B-4E4A-A725-86E82C6D11FC\}").attr("width","100%");

Source of inspiration: jquery escape square brackets to select element

or better, see Milind Anantwar answer use $("[id='anything here']")

Community
  • 1
  • 1
Snake Eyes
  • 15,519
  • 32
  • 105
  • 203