Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda