Posted By

dubogii on 05/17/11


Tagged

attributes


Versions (?)

Working with Attributes


 / Published in: jQuery
 

URL: http://css-tricks.com/snippets/jquery/working-with-attributes/

  1. Setting Single Attribute
  2. $("img").attr("src", "/images/banner.jpg");
  3.  
  4.  
  5. Setting Single Attribute (with function)
  6. $("div").attr("id", function (arr) {
  7. return "div-id" + arr;
  8. })
  9.  
  10.  
  11. Setting Multiple Attributes
  12. $("img").attr({
  13. src: "/images/banner.jpg",
  14. title: "banner",
  15. alt: "banner"
  16. });
  17.  
  18.  
  19. Getting Attribute
  20. var $source = $("img").attr("src");

Report this snippet  

You need to login to post a comment.