テーブル行に id を持つボタンがありますbtn_number_$i
。row_$i
ボタンをクリックすると、最初は非表示になっているid を持つテーブル行を表示したいと思います。
2 つのテーブル行を作成するための PHP コードを次に示します。
echo "<tr><td>"."<button id= \"btn_number_$i\" class='btn info toggler' >Info <i class='icon-arrow-down'></i></button>"."</td></tr>";
echo "<tr id='row_$i' class='info_row'><td>Hello There!!</td></tr>";
以下は私のjQueryコードです。同様の名前の行IDを作成して実行しようとし.show
ています。しかし、私は望ましい結果を得ていません。
$(function () {
$('.info_row').hide(); // first I need to hide all the second rows.
$('.toggler').click(function () {
var currentId = $(this).attr('id');
console.log(currentId);
var lastChar = currentId.substr(currentId.length - 1); //Herein I am trying to extract the last character from btn_number_$i which is $i and then appending it with 'row_'
var rowId = 'row_' + lastChar;
console.log(rowId); // I am able to get the current value in console log.
$('#rowId').show(); // But even after all that i am not able to show the element.
});
});
どんな助けでも感謝します。