Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- How to Master JavaScript


Fotiman - 8:57 pm on Oct 21, 2010 (gmt 0)



3.) In regards to innerHTML not being reliable try scripting with content loaded via AJAX and "added" to the DOM via innerHTML.

I whipped up a quick example to test this. I used jQuery to simplify the example. When the page loads, it will attach an event listener to the button. When the button is clicked, it will load in some content from another file, and set that to the innerHTML value. It will then find the newly added element (using getElementById) and attach an onclick event handler which will simply throw up an alert to let us know it worked. This worked 100% of the time I tried it.
File 1:

<DOCTYPE html>
<html>
<head>
<title>innerHTML Testing</title>
</head>
<body>
<p>In regards to innerHTML not being reliable try scripting with content loaded
via AJAX and "added" to the DOM via innerHTML. It proves to be a 50/50 chance
hit-or-miss in my experience. I can't think of anything really specific since
working with the DOM alleviated the issues and that was about a year and a half
ago for me. I may have an older build of Version 2.9 that still uses innerHTML
somewhere so if you'd like me to look in to that I'll see if I can find an example.
</p>
<input type="button" id="loadContent" value="Load Content" >
<div id="dynamicContent"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
// Attach event listener to button
$('#loadContent').click(function () {
$.get('snippet.htm', function (data) {
var dynamicContent = document.getElementById('dynamicContent'),
foo;
// Load some dynamic content and use innerHTML to add it to this document
dynamicContent.innerHTML = data; // <a id='foo' href='#'>Foo</a>
// Now find the newly added content and attach an onclick handler
foo = document.getElementById('foo');
foo.onclick = function () {
alert('It worked');
return false;
};
});
});
});
</script>
</body>
</html>


snippet.htm

<a id='foo' href='#'>Foo</a>



Actually it is a proprietary Microsoft method that so happens to be supported by all the browsers.

Proprietary, by definition, would mean that it was Microsoft specific. If no other browsers implemented innerHTML, then it would be a proprietary Microsoft method. Originally, yes, it was a proprietary method, but other browsers quickly saw the value of it and added support for it.


In regards to it being added to HTML5, that's JScript, what is JScript doing in an HTML specification?

No, it's not JScript, it's part of the HTML5 DOM. This is a new attribute of HTMLDocument and HTMLElement. It is a serialization of the node's children, and when set will replace the child nodes of the document/element with the parsed value passed in.


4?.) I've read that you can't actually get a 56K connection over the phone lines because of certain laws hence why a 56K modem is limited to 36K speeds. With my 56K modem I never got more then 4.7KB a sec which is 37,600 kilobits because I remember comparing the speed to when I got my first cable modem and was like whoa.

With V.90 technology, the effective download rate is limited to 56 kbps. U.S. government regulations limit the max to 53.3 kbps. Back in the day, I used to get 48 kbps pretty consistently. I think it also depends on the condition of the lines between you and the Central Office (CO). Newer technology (V.42 / V.44) adds compression capabilities for (potentially) faster downloads.


Additionally every instance of jQuery I have encountered is over 70KB minimized, not the 26KB you're talking about.

If you don't GZIP it, then yes, it will be about 75.9 KB.


Still if you're willing to get things to work on IE6 why not get things to work for dial-up users and benefit from writing your own code directly?

To be honest, I would not put in extra effort at this point to ensure things work properly on IE6. It now has about 7% market share worldwide (closer to 3.5% in the U.S.). :)
Things will still work for dial up users, they will just have a longer loading time, as expected. With the average page being 320 KB, if my total page weight is less than that, then I've provided an above average experience for those modem users.
:)


Thread source:: http://www.webmasterworld.com/javascript/4216573.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com