Giri
Giri

Reputation: 4909

jquery insertafter multidimensional array

I have a text form field. It can be cloned/duplicated. It generates name tag like user[name][1][1],user[name][2][1],user[name][3][1] etc...

I want to append a link next to that text fields using jquery. I tried like this..

<script type="text/javascript">
$(function(){
    $('<a href="#">Example link</a>').insertAfter('input[name="user\[name\]\[\]\[\]"]')
});
</script>

But its not working. Can anyone help me?. Thanks

Upvotes: 0

Views: 129

Answers (1)

charlietfl
charlietfl

Reputation: 171669

Per the jQuery selector docs, special characters need to be escaped with double backslash. For all of the elements at once you can use the startsWith selector and do:

$('input[name^="user\\[name\\]"]');

DEMO: http://jsfiddle.net/dpJZE/2/

API selector docs: http://api.jquery.com/category/selectors/

Read top paragraph regarding escaping

Upvotes: 1

Related Questions