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
  • 356,200
  • 43
  • 426
  • 500
  • 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 <- Couldn't find a single working solution online. I reference it here in case you ever come across the same/similar problem. Good luck to ya! – 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
  • 81,290
  • 25
  • 94
  • 125
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
  • 16,287
  • 34
  • 113
  • 221