---
title: "JQuery -- this 和 $(this) 的区别 "
author: "xxtianxiaxing"
date: "2012-03-26T15:56:49Z"
tags: []
categories: ["Web前端"]
slug: "jquery-this-this"
draft: false
lastmod: "2012-03-26T15:58:05Z"
id: 1464126
url: "https://xylonwang.iteye.com/blog/1464126"
---

```
<script type="text/javascript">
$(document).ready(function(){
	$("div").each(function(){
		alert($(this).html() + "----" + this.tagName + "--" + $(this)[0].id);
		alert((this == $(this)[0]));
		$(this).attr("title", $(this).html());
	});
});
</script>
</head>
<body>
<div id="node1">sss1</div>
<div id="node2">sss2</div>
</body>
```

 

#这里的this其实是一个Html元素(div),获取html属性值均可用this.属性名来取值  
#这里的$(this)是一个JQuery对象，可以调用JQuery的方法  
\# this == $(this)\[0] 返回为true  
#JQuery拥有attr()方法可以get/set DOM对象的属性