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?

1
  • 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 -> spyk3lc.blogspot.com/2012/11/… <- 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! Commented Jun 18, 2014 at 14:23

2 Answers 2

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%");
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

Tried this before, but I got the same error, don't know why.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.