javascript - How do add data-attributes in scuccess of Ajax Call -
i having static dom inside web page. trying dynamically add attributes of element of existing dom , insert @ location.here trying far.
$.ajax({ type:"get", async: false, url:contextpath+"/phase/data/getdata", data:postdata, success: function (msg) { // msg ='<div class="row-sml"> // <div class="col col-xs-12 text-right plr30 mb8 displayhide"> // <button type="button" class="btn btn-light-grey cus-btn mt10 rephrase-btn" id="submit-problem-phrase-button">submit</button> // </div>'; $(msg).find('#submit-problem-phrase-button').attr('data',wikitopicid); $('#inserthere').html(msg); }, error:function (xhr, ajaxoptions, thrownerror){ $('.loader02,#overlay-bg,.trans-overlay').hide(); } });
but not working
first must append html code.then change data attribute
simple change order
$('#inserthere').html(msg); $(msg).find('#submit-problem-phrase-button').attr('data', wikitopicid);
like
$.ajax({ type: "get", async: false, url: contextpath + "/phase/data/getdata", data: postdata, success: function(msg) { msg = '<div class="row-sml"> <div class="col col-xs-12 text-right plr30 mb8 displayhide"><button type="button" class="btn btn-light-grey cus-btn mt10 rephrase-btn" id="submit-problem-phrase-button"> submit</button> </div > '; $('#inserthere').html(msg); $(msg).find('#submit-problem-phrase-button').attr('data', wikitopicid); }, error: function(xhr, ajaxoptions, thrownerror) { $('.loader02,#overlay-bg,.trans-overlay').hide(); } });
Comments
Post a Comment