2021-02-06 04:42:36 +00:00
---
id: bad87fee1348bd9aede08817
title: Anida un elemento anchor dentro de un párrafo
challengeType: 0
forumTopicId: 18244
dashedName: nest-an-anchor-element-within-a-paragraph
---
# --description--
Puedes anidar enlaces dentro de otros elementos de texto.
```html
<p>
2021-04-28 22:13:20 +09:00
Here's a <a target="_blank" href="https://www.freecodecamp.org"> link to www.freecodecamp.org</a> for you to follow.
2021-02-06 04:42:36 +00:00
</p>
```
2021-02-16 13:01:20 -08:00
Desglosemos el ejemplo. El texto normal está envuelto en el elemento `p` :
2021-03-21 10:58:20 -06:00
```html
<p> Here's a ... for you to follow. </p>
```
2021-02-16 13:01:20 -08:00
A continuación está el elemento * anchor * `<a>` (que requiere una etiqueta de cierre `</a>` ):
2021-03-21 10:58:20 -06:00
```html
<a> ... </a>
```
2021-02-16 13:01:20 -08:00
`target` es un atributo de etiqueta anchor que especifica dónde abrir el enlace. El valor `_blank` especifica abrir el enlace en una nueva pestaña. El `href` es un atributo de etiqueta anchor que contiene la dirección URL del enlace:
2021-03-21 10:58:20 -06:00
```html
2021-04-23 23:35:27 +09:00
<a href="https://www.freecodecamp.org" target="_blank"> ... </a>
2021-03-21 10:58:20 -06:00
```
2021-02-16 13:01:20 -08:00
2021-04-28 22:13:20 +09:00
El texto, `link to www.freecodecamp.org` , dentro de un elemento `a` se llama <dfn>texto de anclaje</dfn>, y mostrará el enlace para hacer clic:
2021-02-16 13:01:20 -08:00
2021-03-21 10:58:20 -06:00
```html
2021-04-23 23:35:27 +09:00
<a href=" ... " target="...">link to freecodecamp.org</a>
2021-03-21 10:58:20 -06:00
```
2021-02-16 13:01:20 -08:00
El resultado final del ejemplo se verá así:
2021-02-06 04:42:36 +00:00
2021-06-20 22:29:09 +05:30
Here's a <a href="https://www.freecodecamp.org" target="_blank">link to www.freecodecamp.org</a> for you to follow.
2021-02-06 04:42:36 +00:00
# --instructions--
2021-08-21 10:28:22 -07:00
Anida el elemento `a` existente dentro de un nuevo elemento `p` . No vayas a crear una nueva etiqueta de anchor. El nuevo párrafo debe tener un texto que diga `View more cat photos` , donde `cat photos` es un enlace, y el resto es texto regular.
2021-02-06 04:42:36 +00:00
# --hints--
2021-03-14 21:20:39 -06:00
Solo debes tener un elemento `a` .
2021-02-06 04:42:36 +00:00
```js
assert(
2021-03-14 21:20:39 -06:00
$('a').length === 1
);
```
2021-04-23 23:35:27 +09:00
El elemento `a` debe enlazar a "`https://www.freecatphotoapp.com` ".
2021-03-14 21:20:39 -06:00
```js
assert(
2021-04-23 23:35:27 +09:00
$('a[href="https://www.freecatphotoapp.com"]').length === 1
2021-02-06 04:42:36 +00:00
);
```
Tu elemento `a` debe contener el texto anchor de `cat photos`
```js
assert(
$('a')
.text()
.match(/cat\sphotos/gi)
);
```
2021-03-14 21:20:39 -06:00
Debes crear un nuevo elemento `p` . Debe haber al menos 3 etiquetas `p` en tu código HTML.
2021-02-06 04:42:36 +00:00
```js
assert($('p') && $('p').length > 2);
```
2021-03-21 10:58:20 -06:00
Tu elemento `a` debe ser anidado dentro de tu nuevo elemento `p` .
2021-02-06 04:42:36 +00:00
```js
assert(
2021-04-23 23:35:27 +09:00
$('a[href="https://www.freecatphotoapp.com"]').parent().is('p')
2021-02-06 04:42:36 +00:00
);
```
2021-03-14 21:20:39 -06:00
El elemento `p` debe contener el texto `View more` (con un espacio después de él).
2021-02-06 04:42:36 +00:00
```js
assert(
2021-04-23 23:35:27 +09:00
$('a[href="https://www.freecatphotoapp.com"]')
2021-02-06 04:42:36 +00:00
.parent()
.text()
2021-03-04 09:49:46 -08:00
.match(/View\smore\s/gi)
2021-02-06 04:42:36 +00:00
);
```
2021-03-21 10:58:20 -06:00
Tu elemento `a` <em>no</em> debe tener el texto `View more` .
2021-02-06 04:42:36 +00:00
```js
assert(
!$('a')
.text()
.match(/View\smore/gi)
);
```
2021-03-14 21:20:39 -06:00
Cada uno de los elementos `p` debe tener una etiqueta de cierre.
2021-02-06 04:42:36 +00:00
```js
assert(
code.match(/<\/p>/g) &&
code.match(/<p/g) &&
code.match(/<\/p>/g).length === code.match(/<p/g).length
);
```
2021-03-21 10:58:20 -06:00
Cada uno de tus elementos `a` debe tener una etiqueta de cierre.
2021-02-06 04:42:36 +00:00
```js
assert(
code.match(/<\/a>/g) &&
code.match(/<a/g) &&
code.match(/<\/a>/g).length === code.match(/<a/g).length
);
```
# --seed--
## --seed-contents--
```html
<h2>CatPhotoApp</h2>
<main>
2021-04-23 23:35:27 +09:00
<a href="https://www.freecatphotoapp.com" target="_blank">cat photos</a>
2021-02-06 04:42:36 +00:00
2021-09-22 08:34:59 -07:00
<img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back.">
2021-02-06 04:42:36 +00: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>
```
# --solutions--
```html
<h2>CatPhotoApp</h2>
<main>
2021-04-23 23:35:27 +09:00
<p>View more <a target="_blank" href="https://www.freecatphotoapp.com">cat photos</a></p>
2021-02-06 04:42:36 +00:00
2021-09-22 08:34:59 -07:00
<img src="https://cdn.freecodecamp.org/curriculum/cat-photo-app/relaxing-cat.jpg" alt="A cute orange cat lying on its back.">
2021-02-06 04:42:36 +00: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>
```