Reputation: 713
i wish to get the li value when the button beside it is clicked. if the button beside apple is clicked i should get apple on an alert box. i,ve been stuck on this for a day now. any help is appreciated.
<ul>
<li>apple<input type="button" value="show">.
<li>jam<input type="button" value="show">.
<ul>
jquery
$("input[type=button]").click(function()
{
alert( $(this).parent().text());
});
Upvotes: 3
Views: 1627
Reputation: 144659
you should close the li
tags:
<ul>
<li>apple<input type="button" value="show"></li>
<li>jam<input type="button" value="show"></li>
</ul>
Edit: the script works without closing the li's, sounds that jQuery is not loaded correctly.
Upvotes: 4