2018-09-30 23:01:58 +01:00
---
id: bad87fee1348bd9aede08817
title: Nest an Anchor Element within a Paragraph
challengeType: 0
2019-07-31 11:32:23 -07:00
forumTopicId: 18244
2021-01-13 03:31:00 +01:00
dashedName: nest-an-anchor-element-within-a-paragraph
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2019-07-18 17:32:12 +02:00
2018-09-30 23:01:58 +01:00
You can nest links within other text elements.
2019-05-14 01:11:58 -07:00
```html
< p >
2021-04-26 19:04:53 +02:00
Here's a < a target = "_blank" href = "https://www.freecodecamp.org" > link to www.freecodecamp.org< / a > for you to follow.
2019-05-14 01:11:58 -07:00
< / p >
```
2021-02-04 00:04:44 -08:00
Let's break down the example. Normal text is wrapped in the `p` element:
2021-03-19 00:24:09 +01:00
```html
< p > Here's a ... for you to follow. < / p >
```
2021-02-04 00:04:44 -08:00
Next is the *anchor* element `<a>` (which requires a closing tag `</a>` ):
2021-03-19 00:24:09 +01:00
```html
< a > ... < / a >
```
2021-02-04 00:04:44 -08:00
`target` is an anchor tag attribute that specifies where to open the link. The value `_blank` specifies to open the link in a new tab. The `href` is an anchor tag attribute that contains the URL address of the link:
2021-03-19 00:24:09 +01:00
```html
2021-04-22 10:04:23 +05:30
< a href = "https://www.freecodecamp.org" target = "_blank" > ... < / a >
2021-03-19 00:24:09 +01:00
```
2021-02-04 00:04:44 -08:00
2021-04-26 19:04:53 +02:00
The text, `link to www.freecodecamp.org` , within the `a` element is called < dfn > anchor text</ dfn > , and will display the link to click:
2021-02-04 00:04:44 -08:00
2021-03-19 00:24:09 +01:00
```html
2021-04-22 10:04:23 +05:30
< a href = " ... " target = "..." > link to freecodecamp.org< / a >
2021-03-19 00:24:09 +01:00
```
2021-02-04 00:04:44 -08:00
The final output of the example will look like this:
2018-09-30 23:01:58 +01:00
2021-04-26 19:04:53 +02:00
Here's a < a href = "https://www.freecodecamp.org" target = "_blank" > link to www.freecodecamp.org< / a > for you to follow.
2020-11-27 19:02:05 +01:00
# --instructions--
2021-08-18 11:17:50 -04:00
Nest the existing `a` element within a new `p` element. Do not create a new anchor tag. The new paragraph should have text that says `View more cat photos` , where `cat photos` is a link, and the rest is plain text.
2020-11-27 19:02:05 +01:00
# --hints--
2021-03-12 10:09:22 -07:00
You should only have one `a` element.
2020-11-27 19:02:05 +01:00
```js
assert(
2021-03-12 10:09:22 -07:00
$('a').length === 1
);
```
2021-04-22 10:04:23 +05:30
The `a` element should link to "`https://www.freecatphotoapp.com` ".
2021-03-12 10:09:22 -07:00
```js
assert(
2021-04-22 10:04:23 +05:30
$('a[href="https://www.freecatphotoapp.com"]').length === 1
2020-11-27 19:02:05 +01:00
);
2018-09-30 23:01:58 +01:00
```
2021-02-01 11:56:07 -08:00
Your `a` element should have the anchor text of `cat photos`
2020-11-27 19:02:05 +01:00
```js
assert(
$('a')
.text()
.match(/cat\sphotos/gi)
);
```
2018-09-30 23:01:58 +01:00
2021-03-12 10:09:22 -07:00
You should create a new `p` element. There should be at least 3 total `p` tags in your HTML code.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert($('p') & & $('p').length > 2);
```
Your `a` element should be nested within your new `p` element.
```js
assert(
2021-04-22 10:04:23 +05:30
$('a[href="https://www.freecatphotoapp.com"]').parent().is('p')
2020-11-27 19:02:05 +01:00
);
```
2021-02-01 11:56:07 -08:00
Your `p` element should have the text `View more ` (with a space after it).
2020-11-27 19:02:05 +01:00
```js
assert(
2021-04-22 10:04:23 +05:30
$('a[href="https://www.freecatphotoapp.com"]')
2020-11-27 19:02:05 +01:00
.parent()
.text()
2021-02-26 22:17:47 +01:00
.match(/View\smore\s/gi)
2020-11-27 19:02:05 +01:00
);
```
2021-02-01 11:56:07 -08:00
Your `a` element should < em > not</ em > have the text `View more` .
2020-11-27 19:02:05 +01:00
```js
assert(
!$('a')
.text()
.match(/View\smore/gi)
);
```
Each of your `p` elements should have a closing tag.
```js
assert(
code.match(/< \/p > /g) &&
code.match(/< p / g ) & &
code.match(/< \/p > /g).length === code.match(/< p / g ). length
);
```
Each of your `a` elements should have a closing tag.
```js
assert(
code.match(/< \/a > /g) &&
code.match(/< a / g ) & &
code.match(/< \/a > /g).length === code.match(/< a / g ). length
);
```
# --seed--
## --seed-contents--
2018-09-30 23:01:58 +01:00
```html
< h2 > CatPhotoApp< / h2 >
< main >
2018-10-08 01:01:53 +01:00
2021-04-22 10:04:23 +05:30
< a href = "https://www.freecatphotoapp.com" target = "_blank" > cat photos< / a >
2018-10-08 01:01:53 +01:00
2021-09-21 23:46:55 +09:00
< img src = "https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt = "A cute orange cat lying on its back." >
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
< p > Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.< / p >
< p > Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.< / p >
< / main >
```
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
2019-04-22 02:07:05 -04:00
```html
< h2 > CatPhotoApp< / h2 >
< main >
2021-04-22 10:04:23 +05:30
< p > View more < a target = "_blank" href = "https://www.freecatphotoapp.com" > cat photos< / a > < / p >
2019-07-18 17:32:12 +02:00
2021-09-21 23:46:55 +09:00
< img src = "https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt = "A cute orange cat lying on its back." >
2019-07-18 17:32:12 +02:00
2019-04-22 02:07:05 -04:00
< p > Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase the red dot, hairball run catnip eat the grass sniff.< / p >
< p > Purr jump eat the grass rip the couch scratched sunbathe, shed everywhere rip the couch sleep in the sink fluffy fur catnip scratched.< / p >
< / main >
2018-09-30 23:01:58 +01:00
```