8
$("#note_content").dialog({
            title: "Note",
            modal: true,
            width:'auto',
            height:'auto',
            resizable:false,

            open: function(){
                var note_text = $('#note_content').attr('note_text');
     }
}

In my code I am trying set note_text as content of dialog, any idea how could I do this?

2 Answers 2

19

You can try this: DEMO

var SplitText = "Title"
var $dialog = $('<div></div>')
    .html(SplitText )
    .dialog({
        height: 500,
        width: 600,
        title: 'Title'});

$dialog.dialog('open');

$dialog.html('Some text');
​

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

Comments

4

You should have a content place holder inside your dialog, for example:

<div id="noteContent" title="Basic dialog">
   <p id="contentholder"> This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>

$("#note_content").dialog({
    title: "Note",
    modal: true,
    width:'auto',
    height:'auto',
    resizable:false,

    open: function(){
        var note_text = $('#note_content').attr('note_text');
       $("#contentholder").val(note_text)
    }
}

You had your note_text assigned to a variable in this line:

var note_text = $('#note_content').attr('note_text');

However, you didn't assign the note_text variable to the placeholder.

1 Comment

Your solution is correct. however .val() doesn't work on <p> tags. you need to use .text() function to overwrite the content.

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.