Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between innerhtml and outerhtml in cocoa WebView

I am using cocoa webview for rich text editing in my application. Just confused with innerHtml and outerHtml method avaiable in webkit.

Can anyone explain what is the difference between

[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerHTML];

AND

[(DOMHTMLElement *)[[[webView mainFrame] DOMDocument] documentElement] outerText];
like image 263
sach Avatar asked Jan 10 '13 10:01

sach


2 Answers

innerHTML is a property of a DOM element that represents the HTML inside the element, i.e. between the opening and closing tags. It has been widely copied, however implementations vary (probably because it has no published standard[1]) particularly in how they treat element attributes.

outerHTML is similar to innerHTML, it is an element property that includes the opening an closing tags as well as the content. It hasn't been as widely copied as innerHTML so it remains more-or-less IE only.

<p id="pid">welcome</p>

innerHTML of element "pid" == welcome
outerHTML of element "pid" == <p id="pid">welcome</p>

and whereAs

innerText The textual content of the container.

outerText Same as innerText when accessed for read; replaces the whole element when assigned a new value.

<p id="pid">welcome</p>

innerText of element "pid" == welcome
outerText of element "pid" == welcome
like image 186
laxonline Avatar answered Nov 06 '22 21:11

laxonline


Suppose we have a page loaded to webview with html

<html>
<head><title>Your Title</title></head>
<body>
<h1>Heading</h1>
<p id="para" >hi <b>Your_Name</b></p>
</body>
<html>

NOW.

[(DOMHTMLElement *)[[webView mainFrame] DOMDocument] documentElement] 

will returen the DOMHTMLElement "html" and

outerHTML will return the complete html as

<html>
<head><title>Your Title</title></head>
<body>
<h1>Heading</hi>
<p id="para">hi <b>Your_Name</b></p>
</body>
<html>

outerText will return html as

Heading hi Your_Name

for example if we take example of p tag in this case

outerHTML will return - <p id="para">hi <b>Your_Name</b></p>

outerText will return - hi Your_Name

innerHTML will return - hi <b>Your_Name</b>

innerText will return - hi Your_Name

i have explained it with the help of example where definition for these 4 terms already explained in the answer below.

like image 31
robin.cssoft Avatar answered Nov 06 '22 21:11

robin.cssoft