Whing Dela Cruz
asked on
innerHTML
Hi experts,
This code allows to put in an alert the input type="text" next to the button. But what about innerHTML? What I mean is that if not input text? I remove the input text and change to <td>55</td>. Here I want to read 55, which part of this code should i change? alert($(this).closest('tr' ).find('in put').val( )); Thank you, experts!
<script src="http://code.jquery.com/jquery.js"></script>
<script>$(function() {
$('button').click(function () {
alert($(this).closest('tr' ).find('in put').val( ));
});
});
</script>
This code allows to put in an alert the input type="text" next to the button. But what about innerHTML? What I mean is that if not input text? I remove the input text and change to <td>55</td>. Here I want to read 55, which part of this code should i change? alert($(this).closest('tr'
<script src="http://code.jquery.com/jquery.js"></script>
<script>$(function() {
$('button').click(function
alert($(this).closest('tr'
});
});
</script>
ASKER
Hello Heilo,
Sorry for not explaining well my target. This is what I'm looking for. I have to cells on a table, Cell(button) and td(itself)
<tr>
<td><button class="Addbutton">Try it</button></td>
<td>123</td>
</tr>
Now, here I want to put the 123 to the messagebox or alert upon pressing the button. The codes you gave will get the value of the button itself as I tried and tested it. Thank you!
Sorry for not explaining well my target. This is what I'm looking for. I have to cells on a table, Cell(button) and td(itself)
<tr>
<td><button class="Addbutton">Try it</button></td>
<td>123</td>
</tr>
Now, here I want to put the 123 to the messagebox or alert upon pressing the button. The codes you gave will get the value of the button itself as I tried and tested it. Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfectly correct, sorry for not looking the codes well!
ASKER
Thank you Heilo for helping me solve the problem. More power to you and God bless!
>> Thank you Heilo
It's Hielo, and you are welcome.
It's Hielo, and you are welcome.
Although it's already answered, here's a solution similar to what I had for your previous question, using plain JavaScript.
test2.html
test2.html
for non-form elements -- ex: <td><span>55</span></td> -- you can use either .text() or .html():
Open in new window