kastulo
kastulo

Reputation: 851

Select previous text field of a clicked element

I have the following table, with one row, two columns, in one column i have a text field, in the other one a simple button, i haved the text field 'disabled' and i want to enable it the button is pressed...

 <table id="tabla_busqueda">  
 <tr>
     <td><input type="text" value="2"></td>   //This text field is disabled
     <td><button class="editar_campo">Click Me</button></td>
 </tr>
 </table

i have the following:

 $('body').on('click', '#tabla_busqueda .editar_campo', function(){

    $(this).prev('input[type=text]').removeAttr('disabled');

});

but it's not working

any ideas why?

thanks in advance

Upvotes: 0

Views: 62

Answers (1)

adeneo
adeneo

Reputation: 318182

The elements are wrapped in td, so you'll need to do some more traversing, and use prop() :

$('body').on('click', '.editar_campo', function(){
    $(this).closest('td')
           .prev('td')
           .find('input[type="text"]')
           .prop('disabled', false);
});

Upvotes: 2

Related Questions