1

I have this statement

<div class="divShow">
   <ul id="ulShow">           
     <li>
       <h3 class="CompanyShow">A</h3>
       <h2 class="ShowTitle">S</h2>                
       <input class="ExpShow" type="button" value="Edit">           
     </li>
     <li>
       <h3 class="CompanyShow">A2</h3>
       <h2 class="ShowTitle">T1</h2>
       <input class="ExpShow" type="button" value="Edit">
      <li>
    </ul>
</div>

When I click "Edit" button I have to display the corresponding data.

When I click the "Edit" button of the first list then it should display A, and if I click the second li it should dislay A2.

How can I do this using jQuery?

 $('.EditExp').live('click',function(){
     $('.divShow ul li').each(function(){
         alert($(this).parent().find('h3.CompanyShow').html());                 
     });                 
 });
Jeetendra
  • 205
  • 3
  • 18
Bijaya Khadka
  • 159
  • 3
  • 6
  • 20

2 Answers2

1

This should work for you. The idea here is that I am putting a click handler on all the buttons and then i am choosing the .CompanyShow element that is relative to the button only.

DEMO

$('.ExpShow').on('click', function(){
    var $this = $(this);
    alert(  $this.prevAll('.CompanyShow').text());     
}); // end on click 
gillyspy
  • 1,578
  • 8
  • 14
0
$('.ExpShow').click( function() {
  var html = $(this).closest('li').find('.CompanyShow').html();
  alert( html );
});
Prakash GPz
  • 1,675
  • 4
  • 16
  • 27