innerhtml

How to get innerHTML of this element in javascript?

微笑、不失礼 提交于 2019-12-05 02:24:16
问题 Pretty simple question. I have an element (a tag) which has an onclick to call a javascript function. Amoung other things, I want this function to echo the innerHTML of the element that called it. So, in this case, the innerHTML of the atag. How do I do this? 回答1: <element onClick="alert(this.innerHTML);"> ... </element> 回答2: markup: <element id="foo"> ... </element> js: document.getElementById('foo').addEventListener('click', fn); function fn(){ alert(this.innerHTML); } http://jsfiddle.net

Get IFrame innerHTML using JavaScript

只愿长相守 提交于 2019-12-05 02:23:36
问题 I'm trying to get an IFrame inner HTML using below code. <iframe src="http://www.msn.com" width="100%" height="100%" marginwidth="0" scrolling="no" frameborder="0" id="divInfo" onreadystatechange="MyFunction(this);"></iframe> JavaScript code is function MyFunction(frameObj) { if (frameObj.readyState == "complete") { alert(frameObj.document.body.innerHTML); } } But the alert shows me the html of current document. How can i get the inner HTML of iframe when the frmae ready state is complete. If

jQuery + CSS. How do I compute height and width of innerHTML?

有些话、适合烂在心里 提交于 2019-12-04 15:02:10
I have a typical parent-child div hierarchy for a Web project using jQuery. The child css has not height, this allows it to expand and contract based on the height of the innerHTML. I am programmatically stuffing HTML markup into the innerHTML property of the child. I want to set the height of the parent to match the height of the child after the child has it's markup. How do I do this? I tried: childDiv.innerHTML = content; childDivObject = $(childDiv); parentDivObject = $(parentDiv); parentDivObject.css({ "height" : childDivObject.height() + "px" }); But this did not work. What am I missing?

How to append content to querySelectorAll element with innerHTML/innerText?

人走茶凉 提交于 2019-12-04 11:50:03
I currently have my class element: var frame_2 = document.querySelectorAll(".name"); Currently this div is empty. I now want to "append/add" some content to that div - I had a go with innerHTML + innerText but for some reason nothing seems to be added. Example: frame_2.innerHTML = '<img src="image.gif" />'; and frame_2.innerText = 'some text'; Any suggestions? Im not sure if there are ways of doing the same - or performance'wise something better? this gives you a list of elements that contain the class name var name=document.querySelectorAll(".name"); you want the first element? name[0]

DOM parsing in JavaScript

ぃ、小莉子 提交于 2019-12-04 10:50:05
Some background: I'm developing a web based mobile application using JavaScript. HTML rendering is Safari based. Cross domain policy is disabled, so I can make calls to other domains using XmlHttpRequests. The idea is to parse external HTML and get text content of specific element. In the past I was parsing the text line by line, finding the line I need. Then get the content of the tag which is a substring of that line. This is very troublesome and requires a lot of maintenance each time the target html changes. So now I want to parse the html text into DOM and run css or xpath queries on it.

in general, in javascript, isn't using innerHTML an [in]security issue?

匆匆过客 提交于 2019-12-04 06:06:06
问题 with the DOM and cool new tools such as reactjs , should innerHTML ever be used in a javascript program? using it is a lot like opening oneself to an SQL injection attack, but here it's a cross-site scripting etc. everything needs to be examined and scrubbed before it's used. seems to me innerHTML has the same security issues as eval() and should be avoided for [in]security reasons. (also aesthetically, but that's just me.) 回答1: Yes, innerHTML is often misused and a very common source of

Cannot set document.body.innerHTML of IFrame in Firefox

▼魔方 西西 提交于 2019-12-04 04:50:52
I've looked for a cross-browser way to programmatically set the innerHTML of an IFrame. (As in http://roneiv.wordpress.com/2008/01/18/get-the-content-of-an-iframe-in-javascript-crossbrowser-solution-for-both-ie-and-firefox/ ). I've written some sample code (below), and I can get it to work in Safari and Chrome, but not Firefox. Can anyone help me figure out what I need to do instead (in a portable way)? <html> <body> <div name=FRAME2div id=FRAME2div style="position:absolute; background-color:blue; color:black; border-color:black;border-width:0; left:100px; top:40px; width:200px; height:200px;

innerHTML removing closing slash from image tag

丶灬走出姿态 提交于 2019-12-04 04:48:00
问题 This is very odd. Here is a quick test function: function test_function(){ code = '<img src="http://www.myimage.com/img.jpg" alt="image" />'; alert(code); document.getElementById('test').innerHTML = code; alert(document.getElementById('test').innerHTML); } Running the code above will show /> in the first alert, but the second alert doesn't, it shows just > . So it looks like applying to .innerHTML strips out the forward slash. Any ideas how to stop this from happening? I need the forward

Remove HTML tags from a String in Dart

萝らか妹 提交于 2019-12-04 02:43:41
I’ve been trying to achieve this for a while, I have a string which contains a lot of HTML tags in it which is in some encoded form Like & lt; and & gt; (without the spaces) in between the string. Can anyone assist me in removing those tags so that I can get a plain string? Finally I achieved this using the Dart’s built in html package Here’s how I did it import ‘package:html/parser.dart’; //here goes the function String _parseHtmlString(String htmlString) { var document = parse(htmlString); String parsedString = parse(document.body.text).documentElement.text; return parsedString; } I don’t

Add input fields to div container (javascript)

ⅰ亾dé卋堺 提交于 2019-12-03 22:30:54
I want to add some html data to the end of a div container. Currently, I do it with using innerHtml: <script language="javascript"> var addid = 0; function addInput(id){ var docstyle = document.getElementById('addlist').style.display; if(docstyle == 'none') document.getElementById('addlist').style.display = ''; addid++; var text = "<div id='additem_"+addid+"'><input type='text' size='100' value='' class='buckinput' name='items[]' style='padding:5px;' /> <a href='javascript:void(0);' onclick='addInput("+addid+")' id='addlink_"+addid+"'>add more</a></div>"; document.getElementById('addlist')