1

I just want to ask to those master in jquery..

I have ajax

$.ajax({
    type: "POST",
    url: "URL",
    data: {
        DATA: DATA
    },
    beforeSend: function(){
        //action
    },
    success: function(result){
        $('.className').html(result);
    }
});

It already append the <input type="hidden" class="ClassName" value="1">

I try to use

$('.btnClick').on('click',function(){ $('.ClassName').val() }

but still it didn't get the appended input hidden value is there someone to help me?

2
  • What you want exactly.... ??? Commented Jun 21, 2016 at 10:06
  • Hey, I answered this exact question yesterday. Then it got deleted immediately :(. plus. Try using the notation of $(document).on('click', '.btnClick', funtion...). Otherwise you are hooking up only with already existing elements. Commented Jun 21, 2016 at 10:24

1 Answer 1

2

Take care of the cases. className is not the same as ClassName. Also, an input does not have HTML inside, so calling html on it should not work, use val instead.

$('.className').html(result);

Should be

$('.ClassName').val(result);

Also, take care with the selectors. If you use the class name as a selector and you have multiple input fields with the same class name, the ajax bit will update all fields at once. Later, when you try to retrieve the value like you do, it will show only the value of the first one.

If you only plan on having one input with that class name, then you should probably use an id instead of a class, to avoid future confusions.

<input type="text" name="myname" id="myid" class="myclass" value="1">

Setting the value ...

$('#myid').val(result);

Getting the value ...

thevalue = $('#myid').val();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.