jquery选择器

109 阅读1分钟

选择器的作用是:根据特点的字符串规则获取dom元素。

//全局选择器
$('*').css('font-size','20px')
//id选择器
$('#root').css({border:'1px solid black',margin:'0 auto',width:'1000px'})
//类选择器
$('.a').css('color','red')
//标签选择器
$('p').css('text-decoration', 'underline')
//层级选择器
//子选择器
$('#root>.a').css('text-align','center')
//后代选择器
$('#root .a').css('background','green')
//结构伪类选择器
$('ul>li:odd').css('text-align','right')
$('ul>li:even').css('text-align','left')
//属性选择器
$('p[name="b"]').css('color','orange')

总结:jquery选择器的语法就是css选择器的语法