开发者

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&开发者_Go百科gt;');
    }

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


to alert id...

$(function(){

 $("input").click(function(){

       alert($this.attr('id'));

 });

});

But you have not set id of any of the buttons, so it'll alert with blank message.


try this to get the class

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

http://jsfiddle.net/esYAh/


You mean class probably

$(function(){
    $("input").click(function(){
        alert($(this).attr('class'));
    });
});

demo

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜