0

So basically i need to know how i can append a string to a dialog title.

for example the string is foo.

and if I run

$("#dialogid").dialog("option", "title", "bar")

in the js console, the title should be foobar.

EDIT:

basically this line of code shouldn't change. if i run specifically this line of code, the title will change to foobar

EDIT2:

So i've come up with a solution to my problem, but still i have no idea how could i make it so it would happend at once, not after 10 ms

$(function () {
    $("#dialogid").dialog({})
    $("#dialogid").dialog('option', 'title', 'bar');

    setInterval(function(){ 

        var title123 = $("#dialogid").dialog( "option", "title" );
        var n = title123.indexOf("foo");
        if(n < 0) {
            $("#dialogid").dialog( "option", "title", "foo" + title123);
        }

    }, 10);
});
1
  • my answer sort your issue ? Commented Jun 29, 2015 at 17:23

2 Answers 2

1

here is jsfiddle link http://jsfiddle.net/tridip/rxV8R/18/

$(function () {
    $("#dialog").dialog({})
    //init title with text
    $("#dialog").dialog('option', 'title', 'Foo');

    //later change the text
    $("#dialog").dialog('option', 'title', $("#dialog").dialog('option', 'title')+' Bar');
});

if any area is not clear then aks me please.

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

2 Comments

your example worked, but as i edited above, the line of code i gave, shouldn't change.
when my answer worked then you should mark my answer as right or vote me up. thanks
1

This should work (assuming that you want to append to the pre-existing dialog title):

var existingTitle = $("#dialogid").dialog("option", "title"); 
$("#dialogid").dialog( "option", existingTitle  + "bar" );

2 Comments

this works but is there any option to do it globally? i mean, that if i change the title, always the string will be added to the title, without really adding it.
you could probably add some kind of helper (or even extension) method: call it appendToDialog, and then do similar functionality to that of above. Then, whenever you wanted to set the text (via. appending) you could just call that method.

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.