2013-07-07 46 views
0

我正在尝试更改单击事件中的某个div元素。 我的问题是我该如何选择这个元素? 例如,

$("#a").live('click', function(){ 
$('.b').html('text') // I want to change class 'b' inside $(this).parent() and not all 'b' classes 
}); 
+0

你去那里:http://api.jquery.com/find/。 –

回答

1

这可能做的伎俩:

$(this).find('.b').html('text'); 
1

你可以用一个以上的方式做到这一点!

单程

$('#el').on('click', function(){ 
$(this).parent().find('.something').text('new text'); 
}); 

还有一种方法

$('#el').on('click', function(){ 
$(this).next('.something').text('new text'); //or closest 
}); 

希望这可以帮助!

相关问题