1

The following script should insert the code that is set in an array into a specific div:

$(this).on("click", '[data-action="toggle-cat-edit"]', function() {
  var catid = $(this).data("cate-id");
  var editorHTML = [
    "<div>",
    "<p>hello</p>",
    "</div>"
  ].join("\n");
  $('#edit-category-tools-' + catid).editorHTML;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="edit-category-tools-ID"></div>

I've tried through an alert: if the cate-id is set, the right div is gotten, and it works. But it doesn't include the array. Could someone help me on this? What have I done wrong?

Thanks in advance, I appreciate your effort.

1
  • use .append(editorHTML) or .prepend(editorHTML) Commented Jul 13, 2017 at 23:49

3 Answers 3

4

The line:

$('#edit-category-tools-' + catid).editorHTML;

isn't actually doing anything.

To replace the html in the element use:

$('#edit-category-tools-' + catid).html(editorHTML);

Or to append to the element:

$('#edit-category-tools-' + catid).append(editorHTML);
Sign up to request clarification or add additional context in comments.

Comments

3

You need to pass the HTML to the .html jQuery Function:

$('#edit-category-tools-' + catid).html(editorHTML);

Comments

1
$(this).on("click", '[data-action="toggle-cat-edit"]', function() {
    var catid = $(this).data("cate-id");
    var editorHTML ="<div><p>hello</p></div>";
    $('#edit-category-tools-' + catid).append(editorHTML);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.