jQuery for Web Designers
Illustration by John Hersey

Working with HTML attributes


From:

jQuery for Web Designers

with Joe Chellman

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now

Video: Working with HTML attributes

In this movie, we're going to talk about attributes and properties, two similar sides of a similar and subtle coin. So here's my page, and here's the file controlling it. So the first thing that I'm going to do is just look up here and of course any of these is an HTML attribute. Anything to where we say a name and then give it a value. So, I'm going to look at this first link on the page whose href attribute is set to index.htm. Let's scroll down to my jQuery here at the bottom. When the form submits, I'm not letting it submit and I have some code here.
Expand all | Collapse all
  1. 2m 17s
    1. Welcome
      1m 4s
    2. What you should know
      37s
    3. Using the exercise files
      36s
  2. 11m 59s
    1. jQuery is a JavaScript library?
      1m 15s
    2. When to use jQuery
      2m 51s
    3. Alternatives to jQuery
      1m 24s
    4. Which version of jQuery to use
      1m 50s
    5. How to install jQuery
      3m 21s
    6. Reference materials
      1m 18s
  3. 19m 19s
    1. Getting ready
      2m 26s
    2. Selecting elements to use
      3m 54s
    3. Performing multiple operations on the same line with chaining
      2m 30s
    4. Using classes to find what you're looking for
      3m 52s
    5. Adding, modifying, and removing content dynamically
      4m 3s
    6. Challenge: Form feedback
      1m 12s
    7. Solution: Form feedback
      1m 22s
  4. 18m 28s
    1. Triggering a change based on activity with event binding
      4m 37s
    2. Reading and changing values
      4m 17s
    3. Working with HTML attributes
      4m 55s
    4. Challenge: Dynamic contact form
      1m 27s
    5. Solution: Dynamic contact form
      3m 12s
  5. 16m 42s
    1. Using the Colorbox plugin to build a slideshow gallery
      4m 22s
    2. Implementing Colorbox on your site
      2m 46s
    3. Changing Colorbox options
      5m 53s
    4. Challenge: Convert to a slideshow
      1m 6s
    5. Solution: Convert to a slideshow
      2m 35s
  6. 28m 37s
    1. Using jQuery or CSS to animate elements
      2m 24s
    2. Creating simple jQuery animations
      4m 35s
    3. Animating numeric properties with animate()
      4m 56s
    4. Understanding animation easing
      4m 4s
    5. Putting it together: Flowers in the cart
      6m 4s
    6. Callbacks: What to do when the animation ends
      3m 27s
    7. Challenge: Improve the animation
      1m 3s
    8. Solution: Improve the animation
      2m 4s
  7. 4m 45s
    1. More fun plugins
      2m 38s
    2. What's next: More jQuery
      50s
    3. What's next: More JavaScript
      1m 17s

please wait ...
Watch the Online Video Course jQuery for Web Designers
1h 42m Intermediate Oct 31, 2013

Viewers: in countries Watching now:

Take the next step in your web design career with jQuery, which amplifies JavaScript's power and puts a library of prebuilt functions and a diverse selection of plugins at web designers' fingertips. This course explains what jQuery is, how to install it, and use it to script more interesting, interactive websites. Author Joe Chellman will show you how to use jQuery to add web form usability, audio and video, animation, and other features like slideshow galleries to your existing HTML and CSS-based webpages.

Check out JavaScript for Web Designers for more detailed instruction on JavaScript.

Topics include:
  • What is jQuery?
  • Installing jQuery
  • Performing multiple operations with chaining
  • Using classes
  • Adding, modifying, and removing content dynamically
  • Triggering a change with event binding
  • Creating a dynamic contact form
  • Building a slideshow gallery
  • Creating simple jQuery animations
Subject:
Web
Software:
jQuery
Author:
Joe Chellman

Working with HTML attributes

In this movie, we're going to talk about attributes and properties, two similar sides of a similar and subtle coin. So here's my page, and here's the file controlling it. So the first thing that I'm going to do is just look up here and of course any of these is an HTML attribute. Anything to where we say a name and then give it a value. So, I'm going to look at this first link on the page whose href attribute is set to index.htm. Let's scroll down to my jQuery here at the bottom. When the form submits, I'm not letting it submit and I have some code here.

And the first thing that I'm doing, is selecting the very first a tag on the page, and then I'm using the ATTR, or attribute method to retrieve its atrif attribute. So when I call it this way, with just one argument, it will extract that attribute and return it for me. So, I'm actually going to copy this, and bring it over here to my browser and open the console. So we can just see it right away. And indeed that is index.htm for this first link. And I can use this to set that link as well. So, if I mouse over this right now, you can see down there in the split between the console and the main window.

There's the link. I can call this in a different way. So, if I pass in the name of the attribute and then I pass in a second argument say, make it link to itself. I pass this in as the value and that will change dynamically on the page. Of course it won't change in here, in my actual saved file. But in the rendered version that appears in the window it will change. So now let me mouse over this. And you can see it has changed. And this works on any attribute. You could change the source attribute of an image or any attribute at all. I put this in a console.log, so we can see this later.

Okay, so with attributes, you might think, okay, I know that when I want a check box to appear checked in my HTML, I can set the checked attribute. So for example, I scroll up here to one of these check boxes, and I say I want snowboard. Here, to appear checked when I load the page. Okay. So I'm going to set the checked attribute, using the XML style, I'll save this and reload. Okay, great. The checkbox is checked. But if I want to do this with jQuery, I need to do it differently because, while this is an attribute in the way the HTML is written, in terms of the DOM, it's not considered an attribute.

This is to me, one of the more confusing things about working with forms and when you're working with the DOM. What you're actually doing is changing the checked property in terms of the DOM. A property means anything, generally speaking, that can be set true or false. An attribute refers to one of these actual attribute values. And properties are a special case of that where they can be set true or false. There's a lot more on this in the jQuery documentation. But suffice it to say, that in general practice the properties that you're going to be dealing with are things like whether a checkbox is checked.

Sometimes whether a selectbox is selected, although we know with the value method you don't really deal with that so much. And then whether a forum input is disabled. So looking at this, I have my console.log message, which one the form I submitted will show me a few things. It will show me that first link and then it will show me the value of the checked property for this Backpack Cal input here, and it will do the same thing for this Cycle California input here, using their id's. And I have these all concatenated onto one line in the console, while split up across several lines in my JavaScript for readability.

So if I save this, switch back over and reload I'm going to open up my console, I'm going to check one of these boxes and try to submit this. So first I get that link up here and now I can see that backpack cal is not checked because the checked property is set to false and here's its value. So if I'm doing JavaScript validation of some sort and I'm processing this form using JavaScript or jQuery. What I need to know is whether this thing is checked and then, perhaps, I can deal with its value. So value is not going to be informative in this case when we're dealing with checkboxes. I need to check this property.

So even though this property business is different from checking regular values, there is some similarity. So if I want to change a property, I do this the same way as when I was working with values. I pass in this first argument the name of the property that I want to mess with. And then, it's the second argument, the value. So, in this case, I want to set the check property of this backpack checkbox true. And there it is. The checks. Now, there's one more way that I can do this. I have it commented over here. I'm going to uncomment it. Many of jQuery's methods have different ways that you can use them.

So here I set this property by passing in two arguments. But I can also set multiple properties at the same time by passing in a JavaScript object instead. With the names of the properties that I want to set as the keys and the values over here. So if I save this, and reload. Going to submit this form, and I'm going to get back a bunch of stuff in the console and then backpack should be disabled and checked. So there you go. So look through the jQuery documentation at the different methods that you're working with and you'll see that they're are lots of different ways you can call them for different usage scenarios. And that's an overview of how to work with attributes and with properties.

They can be similar and sometimes a little confusing, but work with them a little bit and the differences will become a lot clearer.

There are currently no FAQs about jQuery for Web Designers.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed jQuery for Web Designers.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.