views:

38

answers:

1

I am using CKEditor for my asp.net mvc (C#) application.

I need to extract a part of html before pasting to the CKEditor.

For Ex, i have the following html ready to be pasted to CKEditor:

<html>
<body>
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                Dummy Content
            </td>
        </tr>
        <tr>
            <td>
                <table width="100%" border="0" id="tabletocopy" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            Actual Content
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</body>
</html>

I need to copy only the html of the table "tabletocopy", not the entire(including body) html, something like:

<table width="100%" border="0" id="tabletocopy" cellpadding="0" cellspacing="0">
   <tr>
      <td>
         Actual Content
      </td>
   </tr>
</table>

I found the paste event of CKEditor, but i am not sure on how to use this for my need.

Any ideas on this?

+2  A: 

On paste event, you will get the html in e.data.html as described in link.

In that event you can extract the html using jquery.

e.data.html = $(e.data.html).find("#tabletocopy").html();
Krunal
Wow, this is cool, but a small change as for my need to get the html including table:ev.data.html = $('<div>').append($(ev.data.html).find("#tabletocopy").clone()).remove().html();
Prasad
@Krunal Mevada thanks for the link, it will prove useful in a short time for me :)
Felipe Alsacreations