Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display Messages with jQuery UI

I saw these on jQuery UI's themes page, and thought they were neat.

I wonder how to display messages with these styles both in a static way and with JavaScript.

Thanks in advance.

like image 427
Tom Tucker Avatar asked Mar 11 '11 00:03

Tom Tucker


1 Answers

Using Chrome Developer Tools, I inspected the HTML of the error message. You can do the same for the other one or you can check out the jQuery UI CSS Framework.

HTML

<div class="ui-widget">
    <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"> 
        <p>
            <span class="ui-icon ui-icon-alert" 
                style="float: left; margin-right: .3em;"></span>
            <strong>Alert:</strong> Sample ui-state-error style.
        </p>
    </div>
</div>

CSS

body {
    font-family: Verdana,Arial,sans-serif;
    font-size: 10px;
}

p {
    margin: 1em 0;   
}

strong {
    font-weight: 900;   
}

You can use the addClass method to add these classes programmatically using JS. Also see the show and hide methods which you can use to show/hide these messages.

<button id="show">Show</button>
<button id="hide">Hide</button>

$("#show").click(function() {
    $(".ui-widget").show();
});

$("#hide").click(function() {
    $(".ui-widget").hide();
});

See fiddle.

like image 72
melhosseiny Avatar answered Sep 23 '22 12:09

melhosseiny