javascript - Problem with at sign in div name -


I have a page in which there are some divisions, each div ID starts with the word divfor and then there is a suffix . These suffixes come from databases just like divorjon, divorjam ... etc.

My problem occurs when I try to load something in that division, causing this problem if it contains @ sign, therefore, if I do something below:

  $ ("# divfor" + divsuffix) .html ('some text goes here.');   

If there is a divname divforjohn , but if there is a divname divforjohn @ x , then it does not make any problem. >

So, how can I address the ID on which his ID is signed @ Or its a range / jquery / bug?

Thx.

element with javascript in id = "divforjohn @x" You can do this via document.querySelectorAll or via jQuery / Sizzle) to @ , like this:

  $ ( '# Divforjohn \\ @ x')   

Demo:

In addition, the accepted answer is incorrect ??? This ID naming rule states that HTML 4 was included in the device. The thing is, Browsers have never implemented it , so these rules in HTML5 are no longer restrictive. Valid characters are completely safe to use in the values ​​for id or category

Unless you know what you are? Are again.

Comments