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

113
Vistas
Why this jQuery parent("form") is not working

I made a form that links a button with from an attribute but it's not hiding the parent("form")

but when I try this it works

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

I don't know whats the problem with this code

$($("[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>

Pls Help me Thanks

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

0

.parent() only selects the direct parent (one level up). .parents() will select all the way up the ancestor chain.

$($("[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 Denunciar

0

You can also use .closest() which will only select the nearest parent that matches instead of all parents.

$($("[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 Denunciar

0

You just need to add an id to your form and grab it with jquery, then calling .hide()

form id="myForm" ....

Add this script tag at the end of the body.

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

I think when we are using jquery, there is no need to make our life hard with complicated selectors.

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