Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

173
Vistas
How to add class into html tag manually by PHP

I want to add class "dropdown-toggle" into <a href="#">Additional< /a> this tag but as there is no class before that's why "str_replate" not working perfectly.

I want to add class for only this tag using php there are also <a> tag but I don't want to add the same class for all. I hope you understand. See my code:

<li id="menu-item-97" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-97">


    <a href="#">Additional</a> ***I want to add class for only this "<a>" tag not others tag***
**after adding the class the tag will be "< a class="dropdown-toggle" href="#">Additional< /a>"***


    <ul class="sub-menu">
        <li id="menu-item-69" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-69">
            <a href="http://localhost/wp-web/simpleshop/checkout/">One</a>
        </li>
        <li id="menu-item-68" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-68">
            <a href="http://localhost/wp-web/simpleshop/cart/">Two</a>
        </li>
        <li id="menu-item-70" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-70">
            <a href="http://localhost/wp-web/simpleshop/my-account/">Three</a>
        </li>
    </ul>
</li>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I prefer using javascript for adding class instead instead of php because it is more convenient and used in every type of extension files.

Here is the answer

<li id="menu-item-97" class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-97">

<a href="#" onclick="myFunction()">Additional</a> ***I want to add class for only this "<a>" tag not others tag***
**after adding the class the tag will be "< a class="dropdown-toggle" href="#">Additional< /a>"***

<ul class="sub-menu">
    <li id="menu-item-69" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-69">
        <a href="http://localhost/wp-web/simpleshop/checkout/">One</a>
    </li>
    <li id="menu-item-68" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-68">
        <a href="http://localhost/wp-web/simpleshop/cart/">Two</a>
    </li>
    <li id="menu-item-70" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-70">
        <a href="http://localhost/wp-web/simpleshop/my-account/">Three</a>
    </li>
  </ul>
</li>

<script>
   function myFunction() {        
     var element = 
       document.getElementById("myDIV");            
       element.classList.add("mystyle");
      
    }
</script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda