Reputation: 31
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?
Upvotes: 1
Views: 1607
Reputation: 4819
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();
Upvotes: 2