Jquery selector problem with IDs have square brackets

I’m using PHP quite often in my work, and have the habits to put the form name in the syntax of array, such as

<input id="product[title]" name="product[title]" type="text" />
<input id="product[price]" name="product[price]" type="text" />
<input id="product[description]" name="product[description]" type="text" />

But the problem happened when I use Jquery selector to select the element

This will not work

$(“#product[title]“)

But this will work

$(“:input[id='product[title]‘]”)

There is another way is escape the square by putting \\ before the
square brackets

$(“#product\\[title\\]“)

Hope that help someone having the same trouble like me.

Related posts:

Share

About number.0