javascript - Changing values with jQuery -
i have following:
<span class="label-info">3</span>
i have following jquery
var replaceit = $(this).closest(':has(.label-info)').find('.label-info').text();
the value of variable single whole number not 3:
ie: 1, 2, 3, 4, 5.
i have tried numerous ways , cannot value change. latest attempt was:
return $(this).closest(':has(.label-info)').html().replace(replaceit, (replaceit - 1));
my end result, subtract 1 whatever current value of "lable-info" is, , switch new result. new span based on value of 3 become.
<span class="label-info">2</span>
how achieve this?
updated code more clarity
html:
<div> <span class="lable-info">3</span> </div> <div> <a class="accept_friend">accept</a> </div>
javascript:
$(document).on("click", "a.accept_friend", function() { var checkvalue = $(this).closest(':has(.name)').find('.name').text(); var removeit = $(this).closest(':has(.item)').find('.item').fadeout(); var replaceit = $(this).closest(':has(.label-info)').find('.label-info').text(); $.ajax({ url: '/includes/accept_friend.php', type: 'post', data: {checkvalue}, success:function(data){ return removeit; $("a.remove_pending").text(function () { return ('.label-info').html().replace(replacei, replaceit); }); }
notes:
i not using id. using class. there multiple classes same name. have call closest.
getting value span, subtracting 1 , updating span(using jquery):
html
<span class="label-info">3</span>
jquery
var n = $(".label-info").text(), n2 = n - 1; $(".label-info").text(n2);
hope helps bit
Comments
Post a Comment