closest, parents

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<ul id="one" class="level-1">
<li class="item-i">I</li>
<li id="ii" class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
<li class="item-3">3</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>
<script src="http://upcdn.b0.upaiyun.com/libs/jquery/jquery-2.0.3.min.js"></script>
<script>
// closest 从元素本身开始,在DOM 树上逐级向上级元素匹配,并返回最先匹配的祖先元素
console.log($('.item-a').closest('ul').attr('class')) // level-2
console.log($('.item-a').closest('li').attr('class')) // item-a
console.log($('.item-a').parents().length) // 5
</script>
</body>
</html>

offset, offsetParent, position

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
*{margin:0;padding:0;}
div{padding:10px;}
#box1,#container1{background:red;}
#box2,#container2{background:green;}
#box3,#container3{background:gray;}
#container2{position:relative;}
</style>
</head>
<body>
<div id="box1">
<div id="box2">
<div id="box3">box3</div>
</div>
</div>
<div id="container1">
<div id="container2">
<div id="container3">container3</div>
</div>
</div>
<script src="http://static01.baomihua.com/js/lib/jquery-1.4.4.min.js?t=20120926.js"></script>
<script>
/**
* offset() 在匹配的元素集合中,获取的第一个元素的当前坐标,或设置每一个元素的坐标,坐标相对于文档
* offsetParent() 获取离指定元素最近的含有定位信息的祖先元素
* position() 获取匹配元素中第一个元素的当前坐标,相对于offset parent的坐标。( 译者注:offset parent指离该元素最近的而且被定位过的祖先元素 )
*/
console.log($('#box3').offset())
console.log($('#box3').offsetParent())
console.log($('#box3').position())
console.log($('#container3').offset())
console.log($('#container3').offsetParent())
console.log($('#container3').position())
</script>
</body>
</html>

width, innerWidth, outerWidth, height, innerHeight, outerHeight

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#box1{background:gray;padding:10px;margin:10px;border:10px solid red;width:100px;height:100px;}
</style>
</head>
<body>
<div id="box1" style="color:red;">box1</div>
<script src="http://static01.baomihua.com/js/lib/jquery-1.4.4.min.js?t=20120926.js"></script>
<script>
/**
* .css('height') 和 .height()之间的区别是后者返回一个没有单位的数值
* box-sizing: border-box
* width() height()
* innerWidth() innerHeight() 包括padding
* outerWidth([includeMargin]) outerHeight([includeMargin]) 包括padding, border, [margin]
*/
console.log($('#box1').css('height'), $('#box1').height())
console.log(document.getElementById('box1').offsetHeight)
</script>
</body>
</html>

【jQuery】jQuery API 过 一 遍的更多相关文章

  1. JavaScript强化教程——jQuery UI API 类别

    ---恢复内容开始--- 主要介绍:JavaScript强化教程​—— jQuery UI API 类别 jQuery UI 在jQuery 内置的特效上添加了一些功能.jQuery UI 支持颜色动 ...

  2. jQuery EasyUI API 中文文档 - ComboGrid 组合表格

    jQuery EasyUI API 中文文档 - ComboGrid 组合表格,需要的朋友可以参考下. 扩展自 $.fn.combo.defaults 和 $.fn.datagrid.defaults ...

  3. jQuery EasyUI API 中文文档 - ValidateBox验证框

    jQuery EasyUI API 中文文档 - ValidateBox验证框,使用jQuery EasyUI的朋友可以参考下.   用 $.fn.validatebox.defaults 重写了 d ...

  4. jQuery EasyUI API 中文文档

    http://www.cnblogs.com/Philoo/tag/jQuery/ 共2页: 1 2 下一页  jQuery EasyUI API 中文文档 - 树表格(TreeGrid) 风流涕淌 ...

  5. jQuery DataTable-JavaScript API

    虽然大多数时候你的Javascript交互将通过使用datatable初始化对象作为描述在使用这个网站的部分,有时,你会发现它有用一些外部控制表.可以使用以下函数从jQuery.dataTable对象 ...

  6. jQuery.localStorage() - jQuery SDK API

    jQuery.localStorage() - jQuery SDK API jQuery.localStorage() From jQuery SDK API   Jump to: navigati ...

  7. jQuery.mobile.changePage() | jQuery Mobile API Documentation

    jQuery.mobile.changePage() | jQuery Mobile API Documentation <script> $.mobile.changePage( &qu ...

  8. JQuery常用API 核心 效果 JQueryHTML 遍历 Event事件

    JQuery 常用API 参考资料:JQuery 官网   jQuery API 中文文档 核心 jQuery 对象 jQuery() 返回匹配的元素集合,无论是通过在DOM的基础上传递的参数还是创建 ...

  9. jquery 常用api 小结2

    *一)jQuery常用方法API实战 (1)DOM简述与分类 A)DOM是一种标准,它独立于平台,语言,浏览器. B)如果项目中,你完全按照DOM标准写代码,你就能在各大主流的浏览器中操作标准控件. ...

  10. jQuery常用API之jQuery选择器

    3.jQuery常用API 3.1 jQuery选择器 3.1.1 jQuery基础选择器 原生JS获取元素的方式很多.很杂,而且兼容性情况不一致,因此jQuery给我做了封装,是获取元素统一了标准 ...

随机推荐

  1. CreateProcess函数具体解释

    CreateProcess说明:WIN32API函数CreateProcess用来创建一个新的进程和它的主线程,这个新进程执行指定的可执行文件. 函数原型:BOOL CreateProcess(    ...

  2. 在Linux上怎么安装和配置Apache Samza

    samza是一个分布式的流式数据处理框架(streaming processing),它是基于Kafka消息队列来实现类实时的流式数据处理的.(准确的说,samza是通过模块化的形式来使用kafka的 ...

  3. 一个类实现多个接口的demo

    //A接口 interface A{ public int getA(); } //B接口 interface B{ public int getB(); } //实现了某个接口必须实现其全部的方法 ...

  4. (转)ECSHOP给分类添加代表图

    转之--http://www.cnblogs.com/wangblognet/archive/2012/12/09/2809916.html ecshop的模板有很多不完善的地方,比如添加商品分类的时 ...

  5. 浏览器中 for in 反射 对象成员 的差异

    http://www.cnblogs.com/_franky/archive/2010/05/08/1730437.html 下面是例子 function test(url, obj) { if($( ...

  6. AutoLayout(转)

    转自    http://blog.sina.com.cn/s/blog_9564cb6e0101wv9o.html controller和View的责任分配: 1.View指定固有的content  ...

  7. 【转】 NSArray copy 问题

    转自:   http://blog.sina.com.cn/s/blog_6b1e4a060102uz0i.html   好久没写博客了,今天看到同事的代码中用到了 copy 这个 方法,之前也有了解 ...

  8. javascript知识图谱

  9. WINFORM的DataGridView使用点滴

    1.如果有超过一屏的数据,想通过关键字查找到相关记录,然后再定位之,做法如下:遍历所有行,把某单元格的值和关键字对比,找到后清除所有选择行,然后把当前行设为选择,然后把grid的CurrentCell ...

  10. 常用排序算法总结(C#版)

    首先,说说几个排序中的概念. 1.稳定排序和非稳定排序  简单地说就是所有相等的数经过某种排序方法后,仍能保持它们在排序之前的相对次序,我们就说这种排序方法是稳定的.反之,就是非稳定的. 比如:一组数 ...