0

I have an instance where a user clicks a table row which opens a jquery dialog. I'd like change the color of this row when the user has closed the window.

I know dialog has a close param which can be a function(), but I am unsure how to reference the TR from that point.

E.G,

$("#myPopup").dialog({
    autoOpen: false,
    close: function(event, ui){

 // I am not sure how to get the TR name at this point.
        $("#TR-ID").css('backgroundColor','red');
    }   
}); 
Jason Wells
  • 887
  • 6
  • 16
  • 33

1 Answers1

0

Working demo http://jsfiddle.net/Tr5fX/ or http://jsfiddle.net/szhqU/

If you can flick your code I can take a look but above demo changes color 3 ways, and it should help.

behaviour plz click on forgot and you will see a dialog pop-ing up. rest feel free to play around

code

$("#forgot").click(function(e) {
    $("#forgot-dialog").dialog("open");
    e.preventDefault();
});

$("#forgot-dialog").dialog({
    modal: true,
    autoOpen: false,
    height: 255,
    width: 300,
    buttons: {
        "Change Table Color": function() {
            $('#hulk').css('background-color', 'yellow');
        },
        Cancel: function() {
            $('#hulk').css('background-color', 'red');
            $(this).dialog("close");
        }
    },
    close: function(){
        $('#hulk').css('background-color', 'blue');
    },
});
Tats_innit
  • 33,991
  • 10
  • 71
  • 77
  • Sorry if I wasn't clear, I know how to reference the CSS property. What I need is a way to reference the calling table row's ID. – Jason Wells Jul 10 '12 at 23:55
  • 1
    @JasonWells No worries `:)` Like this you mean? there will be alert when you close the dialog box: http://jsfiddle.net/BNScP/ **Please note** to get the name attribute you can do this `$('#RowID-Hulk').prop('name')` this will give you table row name. – Tats_innit Jul 10 '12 at 23:57
  • Heh, no.. What I mean is I am calling the dialog from a dynamic table. I will not know the ID of the calling row, therefore I cannot make it explicit. I thought there is a way to reference the calling element through selectors/traversing the DOM but I haven't been able to figure it out. – Jason Wells Jul 11 '12 at 00:00
  • @JasonWells Oh in that case use `.on` and bind the click event of your rows and then just pass `$(this)` which will represent your row, can you please use my demo and make a fiddle I might be able to help you out, `:)` – Tats_innit Jul 11 '12 at 00:02
  • Ah, I actually am binding it through .on, but my opener looks like this. $("#myDivName").dialog.("open");, so are you saying to also pass "this"? – Jason Wells Jul 11 '12 at 00:04
  • 1
    @JasonWells yep nearly, `:)` but something like this http://stackoverflow.com/questions/394491/passing-data-to-a-jquery-ui-dialog if you want flick me a demo I will fix it else the link shows how to pass `this`. hope it helps – Tats_innit Jul 11 '12 at 00:08
  • Thanks! I'll give it a shot. It looks like we can use data. on the dialog, interesting. – Jason Wells Jul 11 '12 at 00:12
  • @JasonWells yearp ! ~:)` you can – Tats_innit Jul 11 '12 at 00:14