このフィドルを機能させるにはどうすればよいですか: http://jsfiddle.net/gAHwW/
function $escape(string) {
return string.replace(/\\(\[|\]\\)/g,'\\\\$1');
}
$(function() {
$('input[type="button"]').click(function() {
alert($escape( $(this).attr('id') )); // to show you what the escape does
$('#' + $(this).attr('id')).hide(); // doesn't work
$('#' + $escape( $(this).attr('id') )).hide(); // doesn't work
$('#alsosquare[]').hide(); // doesn't work
//$(this).hide(); // works
//$('#alsosquare\\[\\]').hide(); // works
});
});
名前/ID で要素を動的に選択する必要があり、それらの名前/ID には角かっこを含めることができます。
ありがとう!