I am fetching data to a table from mysql database using php and jquery. But I want to keep the "details" column hidden, which I want should be slide down(appear ) in the corresponding table row after clicking a button named "show details". The following Image may clear my thought:
The jquery Code I am using for slide down is :
$(document).ready(function(){
$("#get_details").click(function(){
$("#get_details_button").slideToggle("slow");
});
});
The code I am using to fetch data is :
$sub_array = array();
$sub_array[] = $row["id"];
$sub_array[] = $row["product_name"].'<p id="get_details">'.$row["details"].'</p>';
$sub_array[] = '<button type="button" name="get_details_button" id="get_details_button" class="btn btn-success btn-xs get_details_button">Get Details</button>';
$data[] = $sub_array;
}
Please feel free to ask for any additional code if you need.
the html part is here :
<table id="user_data" class="table table-bordered table-striped">
<thead>
<tr>
<th width="30%">Image</th>
<th width="50%">Product Name</th>
<th width="20%">get Details</th>
</tr>
</thead>
</table>
2
Answers
You need to use
class
forp
tag then whenever button is clicked use$(this).closest('tr').find(".get_details")
to getp
tag and show/hide sameDemo Code :
You don’t need any ids to make this work. I don’t know your markup but here is an example. You will need to work it out for your markup.
jquery