tags:

views:

286

answers:

4

Hi there,

I want to add css class on buttons of a jquery dialog box.

Here is my code :

$(document).ready(function(){
      $('#messageBox p').html('bla bla bla. Ok?'); 
      $('#messageBox').dialog({
     modal : true,
     buttons: {
       'Yes': function() {
      doSomething();
      $(this).dialog('close');
       }, 
       'No': function() {
      doAnotherThing();
      $(this).dialog('close');
       }
     }
      });
    });

For example, I would like add ".red" class on my "yes" button.

How can I do that?

Thank you!

+1  A: 

Have you tried the addClass function?

Yacoby
But where to add that addclass function?
rahul
same answer like phoenix... Where can I put the addClass function, because buttons are made by jquery dialog and buttons don't have ID's.
nico_somb
A: 

.addClass function

rtfm :)

Jeff
yeah, i know this function... but I don't know how to use it in my case.
nico_somb
A: 

There's a dialogClass option of the dialog function you can use to specify a css class for the dialog itself. You can give it a unique class name and use this class name to get a reference to any child elements of the dialog. Then, use the selectors to either get a reference to the child buttons by position or by the text it contains (probably more efficient to use the former).

Rich
A: 

I've got the solution, thanks to Rich :

$(document).ready(function(){
      $('#messageBox p').html('bla bla bla. Ok?'); 
      $('#messageBox').dialog({
        modal : true,
     dialogClass: 'dialogButtons',
        buttons: {
          'Yes': function() {
                doSomething();
                $(this).dialog('close');
          }, 
          'No': function() {
                doAnotherThing();
                $(this).dialog('close');
          }
        }
      });
    });
$("div.dialogButtons div button:nth-child(1)").addClass("oneCssClass");
$("div.dialogButtons div button:nth-child(2)").addClass("anotherCssClass");

Solved!

nico_somb