Attributes

We can change the behaviour of our elements using HTML attributes. These go inside the first angled braces.

For example, here is a hyperlink (a stands for anchor, which was the old name for a hyperlink):

<a href="http://www.google.com">Link to Google</a>

Whoa there mister, that’s a funny looking opening <a> tag. Yes, it has extra text inside it to say where the link should point to. We call this an Attribute. The <a> tag has always has an href attribute to say where it should point to.

We’ve put the place we want the link to link to right there inside the <a> tag. It’s an href attribute that tells the <a> tag how to work.

Lots of tags have attributes you can use to change their behavior or appearance. We’ll find out more about this later.

Exercise - Attributes

Extend the previous exercise. There were links to wikipedia. Convert these into actual hyperlinks. Verify they point to the right place.

Further Exercise - a new tab

Add another attribute to your a tags to make them open in a new tab. The attribute is:

target="_blank"

Try this now. Click the link. Does it work?

Do you like Email? Do You Like JavaScript?

Sign up for occasional emails covering modern Web Development topics such as Angular 2 and React. You can unsubscribe at any time.

We totally respect your email privacy

comments powered by Disqus