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

175
Views
Cómo agregar clase en la etiqueta html manualmente por PHP

Quiero agregar la clase "dropdown-toggle" en <a href="#">Additional< /a> esta etiqueta, pero como no hay una clase antes, es por eso que "str_replate" no funciona perfectamente.

Quiero agregar una clase solo para esta etiqueta usando php, también hay una etiqueta <a> pero no quiero agregar la misma clase para todos. Espero que entiendas. Ver mi código:

 <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 answers
Answer question

0

Prefiero usar javascript para agregar clases en lugar de php porque es más conveniente y se usa en todo tipo de archivos de extensión.

aquí está la respuesta

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