Search code examples
jqueryjquery-uijquery-selectors

Is there any way by which I can separately find class using Jquery for each element?


my code is :-

for(i = 1; i <= 4; i++) 

    {
    $('.user_list').append('<li><input type="button" class="user'+ i + '"/></li>');
    }

which gives output:-

<li><input type="button" class="user_1" /><li>
<li><input type="button" class="user_2" /><li>
<li><input type="button" class="user_3" /><li>
<li><input type="button" class="user_4" /><li>

can you tell me what code to write so that when j-query runs and i click any one the buttons and get the corresponding id for the buttons


Solution

  • try this to get the class

    $("input[type='button']").click(function() {
       alert($(this).attr("class"));
    });
    

    http://jsfiddle.net/esYAh/