So is like this , I have few html element like <div class="mainitem" data-id="123456"></div>
with different attribute data-id
. Then, have a button
for calling ajax
. When I hover the mainitem
, I also add data-id
to the button
. So actually like this:
$(".somebtnname").click(function(){
var dataid = $(this).data("id");
$.ajax({
url: base_url + "someapi/" + dataid,
cache: false,
type: "GET",
success: (
function (html) {
//some result
})
});
});
I have checked in console everytime I hover mainitem
the data-id
have added to button
.So I think that the data-id
is different for me to do ajax
, BUT when I hover first mainitem
and click button
, then hover second mainitem
and click, the ajax
result is same as first maintiem
. So I confuse about the data-id
did not change when ajax
.