Code Snippet
Working with Attributes
Setting Single Attribute
$("img").attr("src", "/images/banner.jpg");Setting Single Attribute (with function)
$("div").attr("id", function (arr) {
return "div-id" + arr;
})Setting Multiple Attributes
$("img").attr({
src: "/images/banner.jpg",
title: "banner",
alt: "banner"
});Getting Attribute
var $source = $("img").attr("src");
Just getting into vars with jQuery and because of this I have a question to the last example…is it just your favourite way of naming a variable $source or do I have to do this like this to make it work?
It just appears to be a good way of writing variables that have to do with jQuery return values. I like to use it when setting a jQuery object to a variable — for example, var $elems = $(‘#mydivs’);
This is what I need .
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.