rickypai
rickypai

Reputation: 4016

selecting an array of elements in jQuery

I have a form set up like this in HTML:

<input type="text" name="data[type1][0]" value="" size="20" id="data[type1][0]"/>
<input type="text" name="data[type1][1]" value="" size="20" id="data[type1][1]"/>

I set up this way so $_POST['data'] would become an array in php.

Are there ways to select specific elements or the whole set of elements in jQuery?

I've tried $("#data[type1][0]").css("visibility","visible"); but it doesn't work does not work.

Thanks in advance!

Upvotes: 0

Views: 387

Answers (2)

user479911
user479911

Reputation:

You need to double-escape the brackets

$("#data\\[type1\\]\\[0\\]").css("visibility","visible");

Also, [ and ] are invalid characters in the id-attributes in HTML4/XHTML.

Upvotes: 2

The Scrum Meister
The Scrum Meister

Reputation: 30131

Brackets are jQuery meta-characters, you must escape them with two backslashes:

$("#data\\[type1\\]\\[0\\]").css("visibility","visible");

Upvotes: 4

Related Questions