jQuery <img> set attributes for all <img>s in the page

Description

jQuery <img> set attributes for all <img>s in the page

View in separate window

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>attr demo</title>
<style>
img {//from w ww  . j a v  a  2  s .co  m
  padding: 10px;
}

div {
  color: red;
  font-size: 24px;
}
</style>
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
  <img>
  <img>
  <img>
  <div>
    <b>Attribute of Ajax</b>
  </div>
  <script>
    $("img").attr({
      src : "image3.png",
      title : "jQuery",
      alt : "Logo"
    });
    $("div").text($("img").attr("alt"));
  </script>
</body>
</html>



PreviousNext

Related