2

I try to make my code more modular. Currently I include jspf file which contain code for jQuery Dialog into any required jsp file.

I want to put this HTML code into JS file, so I only need to include one .js file instead of two:

function activateZoomingDialog() {
    var tmpId = ???;
    tmpId.innerHTML = '<input type="text"></input>...';
    $(tmpId).dialog({
        modal: true,
        title: 'Select area size',
        ...
    });
}

How to create and maintain (life-cycle) temporary DOM structure? jQuery solution will be acceptable.

2
  • 2
    var tmpId = $("<div>"); then remove it when you destroy the dialog. Commented May 13, 2013 at 18:05
  • @KevinB Yea. I can remove by tmpId.remove(); jQuery call! +1 Commented May 14, 2013 at 7:59

1 Answer 1

3
function activateZoomingDialog() {
    var tmpId = '<div><input type="text"></input>...</div>';
    $(tmpId).dialog({
        modal: true,
        title: 'Select area size',
        ...
    });
}
Sign up to request clarification or add additional context in comments.

3 Comments

With that in mind (that it automatically appends it to the dom for you), i wonder if the destroy method will actually result in the div being automatically removed, since it wasn't part of the DOM to begin with. Edit: Nope, it doesn't. jQueryUI fails! - jsfiddle.net/mattball/HaxYj
Indeed. jsfiddle.net/mattball/HaxYj You're just too fast for me today :)
Thanks! By putting id into top level element or keeping reference to jQuery $('...') I can remove unused code... +1

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.