I have here a list of items in a table. Each item has a “Select” button on the right. Whenever the user clicks the “Select” button the item or text on the left of the button should display on the span. What happens is when I click the “Select” button all the items is being displayed on the span.
To see the actual scenario: http://jsfiddle.net/HnAnu/
My code is down below:
<html>
<head>
<script type="text/javascript" src="jquery.1.7.2.min.js"></script>
<script type="text/javascript">
$(function() {
$(".btnSelectItem").click(function () {
$("#spanItemDescription").html("<u>"+$(".tdItemDescription").text()+"</u>");
});
});
</script>
</head>
<body>
<div>
<span>Item: </span>
<span id="spanItemDescription">____________________________</span>
</div>
<table border=1>
<tr>
<td class="tdItemDescription">Shin Guard Small</td>
<td><input type="button" class="btnSelectItem" value="Select"/></td>
</tr>
<tr>
<td class="tdItemDescription">Shin Guard Medium</td>
<td><input type="button" class="btnSelectItem" value="Select"/></td>
</tr>
<tr>
<td class="tdItemDescription">Shin Guard Large</td>
<td><input type="button" class="btnSelectItem" value="Select"/></td>
</tr>
</table>
</body>
</html>
Please help me. Thanks in advance.
Please try this
FIDDLE DEMO