shinra tensei
shinra tensei

Reputation: 713

jquery - get li value on button click

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

Answers (1)

Ram
Ram

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.

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

Upvotes: 4

Related Questions