Learning jQuery

Learning jQuery Content, Attributes & Properties

This course is out of date and does not reflect our standards or industry best practices. We now recommend you take the Complete Intro to Web Development, v3 course.

Check out a free preview of the full Learning jQuery course:
The "Content, Attributes & Properties" Lesson is part of the full, Learning jQuery course featured in this preview video. Here's what you'd learn in this lesson:

Get and replace content with html or text. Get and set values on form inputs with val. Caution: script tags will execute when inserted using html Difference between prop (properties) and attr (attributes). Before 1.6 only attr existed. Attributes exist in the DOM and properties are properties of DOM elements (objects). e.g. className is the property, class is the attribute (what you put in your HTML) Boolean attributes can return an actual boolean (instead of string) with prop Creating DOM elements uses attr behind the scenes (not prop) Get attr(“title”). Set with attr(“title”, “my title”). Set multiple at a time with a map attr({title: “my title”, name: “some_name”}) or use functions attr(‘title’, fn) Careful using prop(‘href ’) which returns fully qualified url Demo of DOM link properties (e.g. a.pathname)

Get Unlimited Access Now