Set Image URL, title and alt with Javascript array

Description

The following code shows how to set Image URL, title and alt by passing in associate array to attr function.

Example


<html>
<head>
<script
  src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {<!--from w w w .ja v a 2 s.com-->
    $("img").attr({
      src : "http://www.java2s.com/style/download.png",
      title : "java2s.com",
      alt : "Logo"
    });
    $("div").text($("img").attr("alt"));
  });
</script>
</head>
<body>
<body>
  <img />
  <div></div>
</body>
</html>

Click to view the demo





















Home »
  jQuery »
    jQuery Example »




Animation
DOM
Event
Form
List
Select
Style
Table
Utilities