Home  >  Article  >  Web Front-end  >  How to remove attribute value in html

How to remove attribute value in html

青灯夜游
青灯夜游Original
2021-12-14 15:06:392497browse

Methods to remove attribute values ​​in html: 1. Use the attr() method to set the specified attribute value to an empty string, with the syntax "$(element).attr("Attribute Name","")"; 2. , Use the removeAttr() method to remove the specified attribute, the syntax is "$(element).removeAttr("attribute name")".

How to remove attribute value in html

The operating environment of this tutorial: windows7 system, jquery1.10.2&&HTML5 version, Dell G3 computer.

Remove the attribute value from html

1. Use the attr() method to set the specified attribute value to an empty string

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("img").attr("width","");
  });
});
</script>
</head>
<body>
<img  src="img/2.jpg"    style="max-width:90%"/ alt="How to remove attribute value in html" >
<br />
<button>去除width属性值</button>
</body>
</html>

How to remove attribute value in html

2. Use the removeAttr() method to remove the specified attribute

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("img").removeAttr("width");
  });
});
</script>
</head>
<body>
<img  src="img/2.jpg"    style="max-width:90%"/ alt="How to remove attribute value in html" >
<br />
<button>去除width属性</button>
</body>
</html>

How to remove attribute value in html

Recommended tutorials: html video tutorial, jQuery tutorial (video)

The above is the detailed content of How to remove attribute value in html. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What software is html?Next article:What software is html?