freeCodeCamp/curriculum/challenges/espanol/01-responsive-web-design/basic-html-and-html5/nest-an-anchor-element-with...

4.0 KiB

id title challengeType forumTopicId dashedName
bad87fee1348bd9aede08817 Anida un elemento anchor dentro de un párrafo 0 18244 nest-an-anchor-element-within-a-paragraph

--description--

Puedes anidar enlaces dentro de otros elementos de texto.

<p>
  Here's a <a target="_blank" href="https://www.freecodecamp.org"> link to www.freecodecamp.org</a> for you to follow.
</p>

Desglosemos el ejemplo. El texto normal está envuelto en el elemento p:

<p> Here's a ... for you to follow. </p>

A continuación está el elemento anchor <a> (que requiere una etiqueta de cierre </a>):

<a> ... </a>

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:

<a href="https://www.freecodecamp.org" target="_blank"> ... </a>

El texto, link to www.freecodecamp.org, dentro de un elemento a se llama texto de anclaje, y mostrará el enlace para hacer clic:

<a href=" ... " target="...">link to freecodecamp.org</a>

El resultado final del ejemplo se verá así:

Here's a link to www.freecodecamp.org for you to follow.

--instructions--

Anida el elemento a existente dentro de un nuevo elemento p. 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.

--hints--

Solo debes tener un elemento a.

assert(
  $('a').length  === 1 
);

El elemento a debe enlazar a "https://www.freecatphotoapp.com".

assert(
  $('a[href="https://www.freecatphotoapp.com"]').length  === 1 
);

Tu elemento a debe contener el texto anchor de cat photos

assert(
  $('a')
    .text()
    .match(/cat\sphotos/gi)
);

Debes crear un nuevo elemento p. Debe haber al menos 3 etiquetas p en tu código HTML.

assert($('p') && $('p').length > 2);

Tu elemento a debe ser anidado dentro de tu nuevo elemento p.

assert(
  $('a[href="https://www.freecatphotoapp.com"]').parent().is('p')
);

El elemento p debe contener el texto View more (con un espacio después de él).

assert(
  $('a[href="https://www.freecatphotoapp.com"]')
    .parent()
    .text()
    .match(/View\smore\s/gi)
);

Tu elemento a no debe tener el texto View more.

assert(
  !$('a')
    .text()
    .match(/View\smore/gi)
);

Cada uno de los elementos p debe tener una etiqueta de cierre.

assert(
  code.match(/<\/p>/g) &&
    code.match(/<p/g) &&
    code.match(/<\/p>/g).length === code.match(/<p/g).length
);

Cada uno de tus elementos a debe tener una etiqueta de cierre.

assert(
  code.match(/<\/a>/g) &&
    code.match(/<a/g) &&
    code.match(/<\/a>/g).length === code.match(/<a/g).length
);

--seed--

--seed-contents--

<h2>CatPhotoApp</h2>
<main>

  <a href="https://www.freecatphotoapp.com" target="_blank">cat photos</a>

  <img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">

  <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--

<h2>CatPhotoApp</h2>
<main>
  <p>View more <a target="_blank" href="https://www.freecatphotoapp.com">cat photos</a></p>

  <img src="https://www.bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">

  <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>