javascript - jQuery add dynamic content from one element to another element -


i'm adding livechat website, problem have adds dynamic onclick page gets blocked csp policy.

i have managed work around removing dynamic code , adding own.

what cannot figure out how grab link id can either

id="online-icon" or id="offline-icon" , span class lhc-text-status text

client-side not strong point, apologies if code below mess, can adding above id code.

$(document).ready(function () {     $('body').on('click', '.status-icon', function () {         $(this).closest('#lhc_status_container').remove();          $('<div id="lhc_status_container">' +             '<a id="need add status here" class="status-icon" href="#">' +             '<span class="lhc-text-status">and here</span>' +             '</a>' +             '</div>').appendto("#livechatcase");           $("#online-icon").click(function () {             return window.lh_inst.lh_openchatwindow();         });     }); }); 

below example of how dynamic code added page.

<div id="lhc_status_container"> <a id="online-icon" class="status-icon" href="#" onclick="return lh_inst.lh_openchatwindow()"> <span class="lhc-text-status">live online...</span></a> </div> 

update have managed value of id="need add status here" still working on lhc-text-status

solved problem, code below , if can improve on it appreciated need click live chat div twice before opens

$(document).ready(function () {     $('body').on('click', '.status-icon', function () {         var statusid = $(this).attr('id');         var textstatus = $(".lhc-text-status").text();         $(this).closest('#lhc_status_container').remove();          $('<div id="lhc_status_container">' +             '<a id="'+ statusid +'" class="status-icon" href="#">' +             '<span class="lhc-text-status">' + textstatus +'</span>' +             '</a>' +             '</div>').appendto("#livechatcase");           $(".status-icon").click(function () {             return window.lh_inst.lh_openchatwindow();         });     }); }); 

ok fixed double click issue amended code below

$(document).ready(function () {     $('body').on('click', '.status-icon', function () {         var statusid = $(this).attr('id');         var textstatus = $(".lhc-text-status").text();        // $(this).closest('#lhc_status_container').remove();          $('<div id="lhc_status_container">' +             '<a id="'+ statusid +'" class="status-icon" href="#">' +             '<span class="lhc-text-status">' + textstatus +'</span>' +             '</a>' +             '</div>').appendto("body");          return window.lh_inst.lh_openchatwindow();         // $(".status-icon").click(function () {        //     return window.lh_inst.lh_openchatwindow();         //});     }); }); 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -