jQuery selector special character doesn't work with escape in variable
I have a button onlcick it will get the id of the btn and append the new
cloned row to append to the closest table. I have a jquery function that
when the button class onclick it will get the id of the button and get the
id of the table which is the same name. just different initial. I wasn't
able to get the table since in the variable there are special character in
it.
Now I understand that I have to add '\' in front of the special characer
but it doesn't work when the '\' is in the variable.
so this is working:
$('#form_instance').on('click', '.btn_clone', function () {
var b_id = $(this).attr('id');
var t_id = '#t' +
b_id.substring(1).replace(/[!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~]/g,
"\\\\$&");
//this is just show that it works when I put static table id in it. it
works. but not when i put t_id (the output are the same).
var static = '#t_form1\\/t1';
$(static +' tr').eq(1).clone().find('input')
.val('').end()
.appendTo(static);
});
when I switch t_id with static it doesn't work which I need t_id to work
since I would like to have this function apply to every table with button.
this is my fiddle: http://jsfiddle.net/mishxpie/Ugqmv/2/
any idea?
No comments:
Post a Comment