我有一个跨度的div
<div id="div1">
<span class="">hello</span>
</div>
Run Code Online (Sandbox Code Playgroud)
当我点击div我想改变div的第一个span元素的类
$('#div1').click(function() {
// ... check if first span element inside the div .. if there and change the class..
});
Run Code Online (Sandbox Code Playgroud)
And*_*ong 19
$('#div1').click(function() {
$('span:first', this).prop('class', 'newClassName');
})
Run Code Online (Sandbox Code Playgroud)
http://api.jquery.com/first-selector/
使用
$("div span:first-child")
Run Code Online (Sandbox Code Playgroud)
如下:
$('#div1').click(function() {
$('span:first', this).prop('class', 'ClassName');
})
Run Code Online (Sandbox Code Playgroud)
参考http://api.jquery.com/first-child-selector/
| 归档时间: |
|
| 查看次数: |
37147 次 |
| 最近记录: |