2

I want to clear the dialog title, but $('#dialog').dialog('option', 'title', ' '); doesn't work as expected, it will make the dialog title very thin, what is the proper way to clear the title?

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>jQuery UI Dialog - Default functionality</title>
        <link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/cupertino/jquery-ui.css"/>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
        <script>
            $(function() {
                $("#b1").click(function(){
                    $('#dialog').dialog('option', 'title', 'test');
                });
                $("#b2").click(function(){
                    $('#dialog').dialog('option', 'title', ' ');
                });
                $("#b3").click(function(){
                    alert($('#dialog').dialog('option', 'title'));
                });
                $("#dialog").dialog();
            });
        </script>
    </head>
    <body>
        <div id="dialog">
            <p>This is a dialog.</p>
        </div>
        <input id='b1' type='button' value='set title to test'>
        <input id='b2' type='button' value='clear title'>
        <input id='b3' type='button' value='alert(title);'>
    </body>
</html>

1 Answer 1

2

Just insert a non breaking space, not just a space. I copy/paste it from the wikipedia page:

U+2007   figure space (HTML: &#8199;). Produces a space somewhat equal to the figures (0–9) characters.

I make an interactive sample:

            $(function() {
                $("#b1").click(function(){
                    $('#dialog').dialog('option', 'title', 'test');
                });
                $("#b2").click(function(){
                    $('#dialog').dialog('option', 'title', ' ');
                });
                $("#b3").click(function(){
                    alert($('#dialog').dialog('option', 'title'));
                });
                $("#dialog").dialog();
            });
        <link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/cupertino/jquery-ui.css"/>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
        
        <div id="dialog">
            <p>This is a dialog.</p>
        </div>
        <input id='b1' type='button' value='set title to test'>
        <input id='b2' type='button' value='clear title'>
        <input id='b3' type='button' value='alert(title);'>

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

1 Comment

Thanks, this does work! I actually tried another unicode space character before posting this question but it didn't work, this one does the magic.

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.