JQuery - Jquery Wysiwyg return html as string
I am using the JQuery Wysiwyg editor and I am trying to grab the html that makes up the content area to be stored in the DB. Is there a way to get the html of an element and store it as a string? My code looks like tihs
<iframe id="wysiwyg_IFrame">
<html>
<head></head>
<body>
<ul>
<li>This is a test</li>
</ul>
</body>
</html>
</iframe>
I would like to get a line that starts with <html>....</html>
or only the body <body>...</body>
knows if anyone knows if this is possible? Thanks to
a source to share
I figured out the answer and it was in the terrible Jquery Wysiwyg documentation. In fact, it wasn't even in the documentation that was in the wiki part. To get the content you just need to use the divs name and .va () textareas, so for me it was
$('#wysiwyg').val();
If you want to set the content as I am trying d for eg. take something from db and put it in jquery wysiwyg textarea on page load, you need to use setContent method and it will look like this:
var content = 'place me in the text area';
$('#wysiwyg').wysiwyg('setContent', content);
Thanks for all the answers and yes. html () seems to work in all other cases, but won't work with jquery wysiwyg.
a source to share
You can get the HTML of an element through the jQuery function html
:
var htmlString = $('#wysiwyg_IFrame').html();
Alternatively, just use your own innerHTML
DOMElement property , which is now part of the HTML5 standard and has been supported in all major browsers (including IE - it was actually a Microsoft innovation) for years:
var htmlString = $('#wysiwyg_IFrame')[0].innerHTML;
a source to share
$('#wysiwyg_IFrame').html()
does not work?
Update:
Try .contents()
:
$('#wysiwyg_IFrame').contents().find('body').html()
or
$('#wysiwyg_IFrame').contents().html()
From the docs:
The method
.contents()
can also be used to get the iframe content document if the iframe is on the same domain as the main page.
a source to share