Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Reemplazar en variable una dirección href

Soy desarrollador web principiante. Tengo un pequeño problema con mi código:

 var nodes = document.querySelectorAll('.breadcrumb-item'); if(nodes != undefined && nodes !=''){ var first = nodes[0]; console.log('xxxxxx' , first); }

Es devolverme:

 [Log] xxxxxx <li role="presentation" class="breadcrumb-item"> <a href="#/" class="router-link-active" target="_self"> Home </a> </li>

Necesito comprobar:

  1. si un href es "Inicio", reemplace href de "#/" a "/dashboard"
  2. si un href no es "Inicio", entonces muestre console.log('not find').

¿Cómo puedo hacerlo?

Tengo cadena dinámica. Por ejemplo:

 <li role="presentation" class="breadcrumb-item"> <a href="#/" class="router-link-active" target="_self"> Home </a> </li> <li role="presentation" class="breadcrumb-item"> <a href="#/dogs" class="router-link-active" target="_self"> Dogs </a> </li> <li role="presentation" class="breadcrumb-item"> <a href="#/calls" class="router-link-" target="_self"> calls </a> </li> <li role="presentation" class="breadcrumb-item"> <a href="#/catds" class="router-link-" target="_self"> cats </a> </li>

Necesito reemplazar la URL SOLO para Inicio

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

He escrito asumiendo que <a href="#/">Home </a> siempre será el primero en orden. Si va a cambiar su orden, tendrá que cambiar el índice de los nodos dentro del bloque if.

 const nodes = document.querySelectorAll(".breadcrumb-item"); if (nodes.length > 0) { const first = nodes[0].firstElementChild; first.href = "/dashboard"; console.log(first); }
about 4 years ago · Juan Pablo Isaza Report

0

La respuesta anterior es correcta. Tal vez lo siguiente le da una comprensión más clara:

    const nodes = document.querySelectorAll('.breadcrumb-item');

    if (nodos.longitud > 0) {
      const primero = nodos[0].firstElementChild;
      let currentUrlTitle = first.text.trim().toLowerCase();
  
      if (currentUrlTitle == 'inicio') {
        consola.log(primero.texto);
        primero.href = '/panel';
        consola.log(primero.href);
      } más {
        console.log(actualUrlTitle);
      }
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!