load jquery function from a href onclick

Posted by QuBaR on Stack Overflow See other posts from Stack Overflow or by QuBaR
Published on 2010-05-18T07:54:06Z Indexed on 2010/05/18 8:00 UTC
Read the original article Hit count: 716

I have a html table with a column per row with this html code inside the tags:

 <a onclick="modalDialog(this); return false;" href="javascript:void(0)">17795</a>
    <div style="display: none;" class="MessageDataDiv">
     some text to show up in my jquery modal window when function modaldialog is clicked.
    </div>

And the jquery function that is called when onclick is fired within the a href link

function modalDialog(event) {
        $('a.message').click(function () {
         var div = new $(this).closest("td").find(".MessageDataDiv").clone();
         div.show().dialog();
          event.preventDefault();
        });
    }

Can anyone help me with some advice how to write the jquery function more correct so the function only fires one time when the linked is clicked. I need to have the jquery function modalDialog as a separate function because the html table use ajax partial rendering...

The problem is when i click the a href link first time nothing happens, second click on the links gives med two modal dialog and third click gives me three modal dialog and so on...

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about partial-views