美文网首页
JQuery选择器

JQuery选择器

作者: 米酒真香 | 来源:发表于2018-02-23 20:24 被阅读9次

按标签名选择:$('li')$('header ul li')
按ID选:$('#header')
按class选:$('.header')$('.header ul li')
选中所有标签为img的元素:$('img')
选中标签为img的第1个元素:$('img:first')$('img:eq(0)')
选中标签为img的最后1个元素:$('img:last')
选中标签为img的第3个元素:$('img:first')$('img:eq(2)')
选中标签为img的元素的所有索引号为奇数的项:$('img:odd')
选中标签为img的元素的所有索引号为偶数的项:$('img:even')
选中标签为img的元素的所有索引号小于2的项(即0、1前2项):$('img:lt(2)')
选中标签为img的元素的所有索引号大于3的项(即索引号4以后的项):$('img:gt(3)')
$('ul li:nth-child(1)').addClass('shadow');ul下的第一个li子元素添加class. nth-child(n)的参数n是从1开始,不是索引号,n为1即是第1个
$('ul li:nth-child(odd)').addClass('shadow');所有奇数位
$('ul li:nth-child(even)').addClass('shadow');所有偶数位
$('li img').eq(1).addClass('img-circle');第2个
$('li img').eq(-1).addClass('img-circle');倒数第一个
$('li img').css({width:'80px',border:'3px solid black'});li下的img元素设置宽带和边框
$('li img').css('width','+=20px');li下的img元素的宽度在原来的基础上再加20px
获取li下的img元素的宽度:$('li img').css('width');或者$('li img').width()
设置li下的img元素的宽度为100px:$('li img').css('width','100px');或者$('li img').width('100px');

<div class="box">
    <img src="image.jpg" alt="" />
</div>

$('img').offset();对象相对于文档的位置
$('img').position();对象相对于其父元素的位置

相关文章

  • jquery选择器书目录

    jquery选择器-基本选择器 jquery选择器-层级选择器 jquery选择器-基本过滤选择器 jquery选...

  • JQUERY一

    jQuery 元素选择器 jQuery 属性选择器 jQuery CSS 选择器 jQuery 事件 jQuery...

  • jQuser有选择器

    jQuery基本选择器 jQuery过滤选择器 jQuery层级选择器 jQuery筛选选择器(方法)

  • 选择器

    jQuery 元素选择器 jQuery 属性选择器 jQuery CSS 选择器

  • jQuery 基础

    jQuery jQuery操作DOM jQuery的选择器 基本选择器 层级选择器 过滤选择器 jQuery操作样...

  • jQuery

    jQuery jQuery操作DOM jQuery的选择器 基本选择器 层级选择器 过滤选择器 jQuery操作样...

  • jQuery选择器

    一、jQuery常用选择器 二、jQuery选择器优势 三、jQuery常用基本选择器 四、jQuery常用层次选...

  • JQuery基础知识

    jQuery操作DOM jQuery的选择器 基本选择器 层级选择器 过滤选择器 jQuery操作样式 css操作...

  • jQuery相关知识

    1、什么是jQuery选择器? jQuery选择器

  • jQuery选择器

    jQuery选择器 jQuery选择器完全继承了CSS的风格。学会使用选择器是学习jQuery的基础,jQuery...

网友评论

      本文标题:JQuery选择器

      本文链接:https://www.haomeiwen.com/subject/qsrxxftx.html