Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you can put the viewContent inside #mainWrap using javascript. just make sure the DOM is loaded wrapping your js code with $(document).ready() and add:</p> <pre><code>$('#mainWrap').html(viewContent); </code></pre> <p>at the end of your function.</p> <pre><code>$(document).ready(function () { var getSavedContent = '&lt;?php echo json_encode($IdLessContent); ?&gt;'; var trimmedCont=($.trim(getSavedContent).slice(1)); //console.log(trimmedCont); var lengthCont= trimmedCont.length; var trimmedCont=$.trim(trimmedCont.slice(0,lengthCont-1)); console.log(trimmedCont); var test = $('&lt;div class="addId"&gt;'); test.append(trimmedCont); //console.log(test.html()); test.children().each(function(index, value) { $(this).attr('id', "com-"+randomString()); }); //console.log(test.html()); viewContent = test.html(); // put viewContent in the innerHtml of your wrapper $('#mainWrap').html(viewContent); </code></pre> <p>});</p> <p>if you need to send back info to the server you have to do it with ajax. I added a javascript function addId() that will be invoked on click on one of the elements. the new code is:</p> <pre><code>$(document).ready(function () { var getSavedContent = '&lt;?php echo json_encode($IdLessContent); ?&gt;'; var trimmedCont=($.trim(getSavedContent).slice(1)); //console.log(trimmedCont); var lengthCont= trimmedCont.length; var trimmedCont=$.trim(trimmedCont.slice(0,lengthCont-1)); console.log(trimmedCont); var test = $('&lt;div class="addId"&gt;'); test.append(trimmedCont); //console.log(test.html()); test.children().each(function(index, value) { $(this).attr('id', "com-"+randomString()); }); //console.log(test.html()); viewContent = test.html(); // put viewContent in the innerHtml of your wrapper $('#mainWrap').html(viewContent); $('#mainWrap .addId').children().click(function({ addId(this); })); } addId = function(elem){ // elem is the child element you clicked on // $(elem).attr('id') should be "com-[randomString]" $.ajax({ type: "POST", url: "path/to/php/script", // update id PHP script data: data, // whatever you need in json format dataType: "json", error: function() { // error function you want to implement errorFunction(); }, success: function(resp) { // do whatever you need with the response from you PHP action } }); }; </code></pre> <p>if you need to to call server with out human interaction just substitute</p> <pre><code>$('#mainWrap .addId').children().click(function({ addId(this); })); </code></pre> <p>with:</p> <pre><code>$('#mainWrap .addId').children().each(function({ addId(this); })); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload