Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery - get li value on button click

Tags:

jquery

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());
  });
like image 234
shinra tensei Avatar asked Jan 23 '26 11:01

shinra tensei


1 Answers

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.

http://jsfiddle.net/D9Jv7/1/

like image 79
undefined Avatar answered Jan 26 '26 03:01

undefined



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!