Reputation: 283
I have an unordered list that has tables in it. The list also uses an image which when clicked on should hide the table. I have the following jQuery code, but it is not working:
$(".glyphicon-remove").click(function () {
var tblId = $(this).attr("id");
// alert(tblId);
var ans = confirm("Are you sure you want to remove this table?");
if(ans == true)
$("#" + tblId).hide();
});
and the list used is as follows:
<ul class="sortable">
<li class="ui-state-default" id="first"><span style="float:right;"class="glyphicon glyphicon-remove"></span><br/>
<table class="rounded-corner">
<thead>
<tr>
<th></th>
<th>Product</th>
<th>Details</th>
<th>Price</th>
<th>Date</th>
<th>Category</th>
<th>User</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="12">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut.</td>
</tr>
</tfoot>
<tbody>
<tr class="odd">
<td><input type="checkbox" name="" /></td>
<td>Box Software</td>
<td>Lorem ipsum dolor sit amet consectetur</td>
<td>45$</td>
<td>10/04/2011</td>
<td>web design</td>
<td>Alex</td>
<td><a href="#"><img src="images/edit.png" alt="" title="" border="0" /></a></td>
<td><a href="#"><img src="images/trash.gif" alt="" title="" border="0" /></a></td>
</tr>
<tr class="even">
<td><input type="checkbox" name="" /></td>
<td>Trial Software</td>
<td>Lorem ipsum dolor sit amet consectetur</td>
<td>155$</td>
<td>12/04/2011</td>
<td>web design</td>
<td>Carrina</td>
<td><a href="#"><img src="images/edit.png" alt="" title="" border="0" /></a></td>
<td><a href="#"><img src="images/trash.gif" alt="" title="" border="0" /></a></td>
</tr>
<tr class="odd">
<td><input type="checkbox" name="" /></td>
<td>Hosting Pack</td>
<td>Lorem ipsum dolor sit amet consectetur</td>
<td>45$</td>
<td>10/04/2011</td>
<td>web design</td>
<td>Alex</td>
<td><a href="#"><img src="images/edit.png" alt="" title="" border="0" /></a></td>
<td><a href="#"><img src="images/trash.gif" alt="" title="" border="0" /></a></td
</tr>
<tr class="even">
<td><input type="checkbox" name="" /></td>
<td>Duo Software</td>
<td>Lorem ipsum dolor sit amet consectetur</td>
<td>745$</td>
<td>10/04/2011</td>
<td>web design</td>
<td>Alex</td>
<td><a href="#"><img src="images/edit.png" alt="" title="" border="0" /></a></td>
<td><a href="#"><img src="images/trash.gif" alt="" title="" border="0" /></a></td
</tr>
<tr class="odd">
<td><input type="checkbox" name="" /></td>
<td>Alavasti Software</td>
<td>Lorem ipsum dolor sit amet consectetur</td>
<td>45$</td>
<td>10/04/2011</td>
<td>web design</td>
<td>John</td>
<td><a href="#"><img src="images/edit.png" alt="" title="" border="0" /></a></td>
<td><a href="#"><img src="images/trash.gif" alt="" title="" border="0" /></a></td
</tr>
<tr class="even">
<td><input type="checkbox" name="" /></td>
<td>Box Software</td>
<td>Lorem ipsum dolor sit amet consectetur</td>
<td>45$</td>
<td>10/04/2011</td>
<td>web design</td>
<td>Doe</td>
<td><a href="#"><img src="images/edit.png" alt="" title="" border="0" /></a></td>
<td><a href="#"><img src="images/trash.gif" alt="" title="" border="0" /></a></td
</tr>
</tbody>
</table>
</li>
<li class="ui-state-default" id="second">2</li>
<li class="ui-state-default" id="third">3</li>
<li class="ui-state-default" id="fourth">4</li>
<li class="ui-state-default" id="fifth">5</li>
<li class="ui-state-default" id="sixth">6</li>
<li class="ui-state-default" id="seventh">7</li>
<li class="ui-state-default" id="eighth">8</li>
<li class="ui-state-default" id="ninth">9</li>
<li class="ui-state-default" id="tenth">10</li>
</ul>
Please help me out.
Upvotes: 0
Views: 60
Reputation: 82241
Try this:
$(".glyphicon-remove").click(function () {
var tblId = $(this).attr("id");
// alert(tblId);
var ans = confirm("Are you sure you want to remove this table?");
if(ans == true)
$(this).siblings('table').hide();
});
Upvotes: 0
Reputation: 38112
You can use:
var tblId = $(this).parent().attr("id");
instead of:
var tblId = $(this).attr("id");
since you want to get the id
of li
element not span
with class glyphicon-remove
Upvotes: 1