Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am completely new to jQuery.

I have written an onclick event like this:

JavaScript
$(document).ready(function () {
         $('body').find('.milestonetable').each(function () {
            var mTable = $(this);
            $(this).find('tr:first').children().eq(0).find('table').find('tr:last').children().eq(0).find('span').on('click', function () {
                var _mid = $(mTable).parent().next('table').find('tbody').find('tr').children().eq(1).find('input').val();
             //some other things to do.
            });

         });
    });



Its working fine. But when I call an ajax, it stops working. I have figured out that I have to write it something like this:

JavaScript
$(document).on('click','.someclassName', function () {  

       });



But I am unable to convert the above code similar to the code below. Kindly help.
Posted
Comments
jaket-cp 9-Feb-15 5:50am    
try something like this:

$(document).ready(function(){
$('.someclassName').click(function(){
//put code here
})
});

1 solution

I didnot understand the question clearely. But still I had a try. Below is the simple code. enhance the same as per your logic.

HTML
<html>
<head>
<script src="C:\\Users\\Downloads\\jquery-2.1.1.js"></script>
<script>
$(document).on('click','.milestonetable',function(){
alert('U clicked on table');
});
</script>
</head>
<body>
<form>

<table class="milestonetable">
<thead>
  <th><td>head1</td> <td>head2</td></th>
<thead>
<tbody>
 <tr><td>1</td> <td>ABC</td></tr>
 <tr><td>2</td> <td>XYZ</td></tr>
</tbody>
</table>

</form>
</body>
</html>


On clicking on table, it is showing alert.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900