0

I'm working with a KENDO control (unimportant i think) that feeds a "script" object to one of its parameters (again also i think unimportant).

What I think IS important, when i fire a popup for the HTML of the scripted object, i see the [DIV] tags: enter image description here

I want to refactor this as a jQuery object and have come up with this code snippet:

var $templateDiv = $('<div></div>')
  .attr({
    "id": "template",
    "type": "text/kendo-x-tmpl"
  })
  .text("#:MaximoId#");
alert($templateDiv.html());

however when I 'alert' the html(), I lose the [DIV] tags.

enter image description here

Yes I see that the original example is embedded in a script while mine is not - ignorant as I am, I feel that my final solution doesn't need to wrap a [DIV] inside a script object?

1 Answer 1

1

jQuery's .html() method returns the same result as native JS innerHTML. It returns what's inside the element. jQuery does not offer a way to get the outer HTML, but you can do it using the native .outerHTML:

var $templateDiv = $('<div></div>')
  .attr({
    "id": "template",
    "type": "text/kendo-x-tmpl"
  })
  .text("#:MaximoId#");
  
alert($templateDiv[0].outerHTML);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Sign up to request clarification or add additional context in comments.

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.