---
title: "jquery-元素属性操作"
author: "小丑鱼0703"
date: "2015-03-03T17:33:43Z"
tags: []
categories: ["Web前端"]
slug: "jquery"
draft: false
lastmod: "2015-03-03T17:50:07Z"
id: 2188202
url: "https://wangjingyi.iteye.com/blog/2188202"
---

**attr(attributeName) 或者attr(attributeName，value) **
  设置或返回第一个匹配元素的属性值


```javascript

<style>
  em { color:blue; font-weight:bold; }
</style>
<p>a<em title="huge, gigantic">large</em> orange</p> 
 The title of the emphasis is:<div></div> 
<script>
var title = $("em").attr("title");
  $("div").text(title);//结果：The title of the emphasis is:huge, gigantic
</script>
```


```javascript

  $("em").attr({'title':'big','value':'me'});  
  $("div").text($("em").attr("title"));//结果：The title of the emphasis is:big 
```

<http://www.css88.com/jqapi-1.9/attr/>

**removeAttr(attributeName) **
  为匹配的元素集合中的每个元素中移除一个属性

    ---对应原生removeAttribute() 函数

```javascript

  $("em").removeAttr("title");
  alert($("em").attr("title"));//undefined
```

<http://www.css88.com/jqapi-1.9/removeAttr/>