Answer the question
In order to leave comments, you need to log in
Why doesn't javascript read changes in selector attribute?
The situation is this. There is a form, it has a button, various fields, including a hidden input field with name="queue". Here is the form code:
<form class="cme text-center" id="f-2" name="MyForm">
<div class="white big-p"><strong>Если еще остались вопросы...</strong></div>
<input data-queue="second" type="text" class="form-control" name="name" placeholder="Ваше имя">
<input data-queue="first" type="text" class="form-control" name="phone" id="phone" placeholder="Номер телефона">
<input name="type" type="hidden" value="2" />
<input name="queue" type="hidden" value=true />
<button id="send_button_s-0" data-queue="Может еще немного о себе?" class="cme-btn btn btn-danger">Заказать консультацию!</button>
<div id="alert-1" class="white mini-p"></div>
<div class="callme-result"></div>
</form>
jQuery.getJSON(folder + 'lib/send.php', { // отправка данных
contentType: 'text/html; charset=utf-8',
cs : cs,
os : os,
ctime : cnt,
}, function(i) {
cmeMsg(form, i.cls, i.message);
if (i.result=='success' && !Boolean($(e).closest('form').find('input[name="queue"]').val())) {
setData('callme-sent', i.time);
form.find('.cme-btn').attr('disabled', 'disabled');
dl('cmeHide', 4);
dl('cmeClr', 5);
} else if (i.result=='success' && Boolean($(e).closest('form').find('input[name="queue"]').val())) {
$(e).closest('form').find('input[name="queue"]').val("false");
$(e).parent().find('input[data-queue="first"]').each(function(){
$(this).slideToggle();
});
$(e).parent().find('input[data-queue="second"]').each(function(){
$(this).slideToggle();
});
$(e).html($(e).attr("data-queue"));
}
});
Answer the question
In order to leave comments, you need to log in
Try writing prop instead of attr
And here you can write data instead of attr and remove the "data-" prefix:$(e).html($(e).data("queue"));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question