HOW TO CHANGE VALUE OF INPUT WITH JQUERY UNDER THIS CLASS?

Andrew Watson

Total Post:39

Points:273
Posted by  Andrew Watson
 1196  View(s)
Ratings:
Rate this:

jQuery:

$('.clickhere').click(function(e){

    e.preventDefault();

    $(this).closest('.row').children('.abc').hide(); // working

    $(this).closest('.row').children('.abc').children('input').value = ''; // not working

    $(this).closest('.bookingrow').children('.addressbox').children('input').value(''); // alternative - not working

});

html

<div class="row">

  <div class='abc'>

     <input type='text' class='unknown' />

  </div>

  <div class="clickhere">hide</div>

</div>

my target is if i click the "clickhere" class, content under "abc" class will hide and whatever content added by customer on those input box, they will be clear.

same html used multiple time on the same form. that's why using "$(this)".
any solution? what i am doing wrong?
Thanks in advance.

  1. jayprakash sharma

    Post:117

    Points:821
    Re: How to change value of input with jquery under this class?

    You need to use .val() to set the value, jQuery methods normally will return a jQuery object not a dom element reference so you would not have a properly called .value.

    $(this).closest('.row').find('.abc input').val('');


    So

    $('.clickhere').click(function (e) {

        e.preventDefault();

        //cache the value of .row since it is used multiple times

        var $row = $(this).closest('.row');

        $row.children('.abc').hide(); // working

        $row.find('.abc input').val('');

    });

      Modified On Mar-15-2016 05:25:04 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!