Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
Alert value dynamically changed attribute

How can i again use this function without refreshing the page ? When i click button data-status equals to 1. but alert(status) returns 0. $(".changestatusItems-" + itemId).attr('data-status', changetostatus); this line change data-status value dynamically. but alert not return new value. alert returns first value after pageload.

<button id="38" data-status="0" type="button" class="changestatusItem changestatusItems-38 btn btn-primary" title="Passive"></button>

$(document).on('click', '.changestatusItem', function() {
    var itemId = $(this).attr("id");
    var status = $(this).data("status");
    if (status == 1) {
        var changetostatus = 0;
    } else if (status == 0) {
        var changetostatus = 1;
    }
    alert(status);
    $.ajax({
        url: "/",
        method: "POST",
        data: {
            itemId: itemId,
            status: status
        },
        success: function(data) {
            $(".changestatusItems-" + itemId).attr('data-status', changetostatus);
        }
    });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!