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

126
Views
Por qué este padre jQuery ("formulario") no funciona

Hice un formulario que vincula un botón con un atributo pero no oculta el parent("form")

pero cuando intento esto funciona

 $($("[editFormContent]").attr("editFormContent")).click(function(e) { e.preventDefault(); alert(); });

No sé cuál es el problema con este código.

 $($("[editFormContent]").attr("editFormContent")).click(function(e) { e.preventDefault(); $(this).parent("form").hide(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="main container"> <div class="breadcrumb col-100"> <h2>UserProfile @<?=$_SESSION['Dname']?></h2> <small><i class="fal fa-home"></i> Home \ Settings \ Account</small> </div> <div class="card col-100 "> <form method="post" editFormContent="#edit"> <table class="col-100"> <tr> <th width="50%"></th> <th width="50%"></th> </tr> <tr> <label> <td>First Name</td> <td> <span class="editFormSpan">Fname Lname</span> </td> </label> </tr> <tr> <td colspan="2"><a href="" id="edit">Edit</a></td> </tr> </table> </form> </div> </div>

Por favor ayúdame gracias

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

0

.parent() solo selecciona el padre directo (un nivel más arriba). .parents() seleccionará todo el camino hacia arriba en la cadena de antepasados.

 $($("[editFormContent]").attr("editFormContent")).click(function(e) { e.preventDefault(); $(this).parents("form").hide(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="main container"> <div class="breadcrumb col-100"> <h2>UserProfile @<?=$_SESSION['Dname']?></h2> <small><i class="fal fa-home"></i> Home \ Settings \ Account</small> </div> <div class="card col-100 "> <form method="post" editFormContent="#edit"> <table class="col-100"> <tr> <th width="50%"></th> <th width="50%"></th> </tr> <tr> <label> <td>First Name</td> <td> <span class="editFormSpan">Fname Lname</span> </td> </label> </tr> <tr> <td colspan="2"><a href="" id="edit">Edit</a></td> </tr> </table> </form> </div> </div>

about 4 years ago · Juan Pablo Isaza Report

0

También puede usar .closest() que solo seleccionará el padre más cercano que coincida en lugar de todos los padres.

 $($("[editFormContent]").attr("editFormContent")).click(function(e) { e.preventDefault(); $(this).closest("form").hide(); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="main container"> <div class="breadcrumb col-100"> <h2>UserProfile @<?=$_SESSION['Dname']?></h2> <small><i class="fal fa-home"></i> Home \ Settings \ Account</small> </div> <div class="card col-100 "> <form method="post" editFormContent="#edit"> <table class="col-100"> <tr> <th width="50%"></th> <th width="50%"></th> </tr> <tr> <label> <td>First Name</td> <td> <span class="editFormSpan">Fname Lname</span> </td> </label> </tr> <tr> <td colspan="2"><a href="" id="edit">Edit</a></td> </tr> </table> </form> </div> </div>

about 4 years ago · Juan Pablo Isaza Report

0

Solo necesita agregar una identificación a su formulario y agarrarlo con jquery, luego llamar a .hide()

formulario id="miFormulario" ....

Agregue esta etiqueta de secuencia de comandos al final del cuerpo.

 <script> $(document).ready(function () { $('#edit').click(function(e){ e.preventDefault(); $('#myForm').hide(); }); }); </script>

Creo que cuando usamos jquery, no hay necesidad de complicarnos la vida con selectores complicados.

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!