{"version":"https://jsonfeed.org/version/1","title":"Aaron Gustafson: Content tagged best practices","description":"The latest 20 posts and links tagged best practices.","home_page_url":"https://www.aaron-gustafson.com","feed_url":"https://www.aaron-gustafson.com/feeds/best-practices.json","author":{"name":"Aaron Gustafson","url":"https://www.aaron-gustafson.com"},"icon":"https://www.aaron-gustafson.com/i/og-logo.png","favicon":"https://www.aaron-gustafson.com/favicon.png","expired":false,"items":[{"id":"https://www.aaron-gustafson.com/notebook/a-web-component-starter-template/","title":"✍🏻 A Production-Ready Web Component Starter Template","summary":"I created a comprehensive starter template for creating production-ready web components with modern tooling, testing, and CI/CD—following Google’s Custom Element Best Practices.","content_html":"<p>Creating a new web component from scratch involves a lot of boilerplate—testing setup, build configuration, linting, CI/CD, documentation structure, and more. After building — and refining/rebuilding — numerous web components, I’ve distilled all that work into a starter template that lets you focus on your component’s functionality rather than project setup.</p>\n<p>The <a href=\"https://github.com/aarongustafson/web-component-starter\">Web Component Starter Template</a> is based on the architecture and patterns I’ve refined across my web component work, incorporating <a href=\"https://web.dev/articles/custom-elements-best-practices\">Google’s Custom Element Best Practices</a> and advice from other web components practitioners including the always-brilliant <a href=\"https://daverupert.com/\">Dave Rupert</a>.</p>\n<h2 id=\"what%E2%80%99s-included\" tabindex=\"-1\"><a class=\"header-anchor\" href=\"#what%E2%80%99s-included\" aria-hidden=\"true\">#</a> What’s included</h2>\n<p>The template provides everything you need to create a production-ready web component:</p>\n<ul>\n<li><strong>Interactive setup wizard</strong> that scaffolds everything for your component.</li>\n<li><strong>Multiple import patterns</strong> supporting both auto-define and manual registration.</li>\n<li><strong>Demo pages</strong> for development, documentation, and CDN examples.</li>\n<li><strong>Code quality tools</strong> including ESLint and Prettier with sensible defaults.</li>\n<li><strong>Modern testing setup</strong> with Vitest, Happy DOM, and coverage reporting.</li>\n<li><strong>CI/CD workflows</strong> for GitHub Actions with automated testing and npm publishing.</li>\n<li><strong>Publishing ready</strong> with proper npm package configuration and OIDC support.</li>\n</ul>\n<h2 id=\"quick-start-with-interactive-setup\" tabindex=\"-1\"><a class=\"header-anchor\" href=\"#quick-start-with-interactive-setup\" aria-hidden=\"true\">#</a> Quick start with interactive setup</h2>\n<p>Getting started is straightforward. If you’re a GitHub user, you can create a new repository directly from the template. Alternatively, clone it locally:</p>\n<pre class=\"language-bash\" tabindex=\"0\"><code class=\"language-bash\"><span class=\"token function\">git</span> clone https://github.com/aarongustafson/web-component-starter.git my-component\n<span class=\"token builtin class-name\">cd</span> my-component\n<span class=\"token function\">npm</span> <span class=\"token function\">install</span>\n<span class=\"token function\">npm</span> run setup</code></pre>\n<p>The setup wizard asks for your component name and description, then automatically:</p>\n<ul>\n<li>Renames all files based on your component name,</li>\n<li>Updates all code and configuration templates with your details,</li>\n<li>Generates a proper README from the included template,</li>\n<li>Cleans up all template-specific files, and</li>\n<li>Initializes the git repository.</li>\n</ul>\n<p>You’re left with a fully scaffolded repository, ready for you to develop your component.</p>\n<h2 id=\"flexible-import-patterns\" tabindex=\"-1\"><a class=\"header-anchor\" href=\"#flexible-import-patterns\" aria-hidden=\"true\">#</a> Flexible import patterns</h2>\n<p>One of the key features is support for multiple registration patterns. Users of your component can choose what works best:</p>\n<p><strong>Manual registration for full control:</strong></p>\n<pre class=\"language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> ComponentNameElement <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@yourscope/component-name'</span><span class=\"token punctuation\">;</span>\n\ncustomElements<span class=\"token punctuation\">.</span><span class=\"token function\">define</span><span class=\"token punctuation\">(</span><span class=\"token string\">'my-custom-name'</span><span class=\"token punctuation\">,</span> ComponentNameElement<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre>\n<p><strong>Auto-define for convenience:</strong></p>\n<pre class=\"language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> <span class=\"token string\">'@yourscope/component-name/define.js'</span><span class=\"token punctuation\">;</span></code></pre>\n<p><strong>Or call the helper directly:</strong></p>\n<pre class=\"language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> defineComponentName <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'@yourscope/component-name/define.js'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">defineComponentName</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre>\n<p>The auto-define approach includes guards to ensure it only runs in browser environments and checks if <code>customElements</code> is available, making it safe for server-side rendered (SSR) scenarios.</p>\n<h2 id=\"testing-made-easy\" tabindex=\"-1\"><a class=\"header-anchor\" href=\"#testing-made-easy\" aria-hidden=\"true\">#</a> Testing made easy</h2>\n<p>The template includes a comprehensive testing setup using Vitest:</p>\n<pre class=\"language-javascript\" tabindex=\"0\"><code class=\"language-javascript\"><span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> describe<span class=\"token punctuation\">,</span> it<span class=\"token punctuation\">,</span> expect <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'vitest'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token function\">describe</span><span class=\"token punctuation\">(</span><span class=\"token string\">'MyComponent'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">it</span><span class=\"token punctuation\">(</span><span class=\"token string\">'should render'</span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">const</span> el <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">createElement</span><span class=\"token punctuation\">(</span><span class=\"token string\">'my-component'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token function\">expect</span><span class=\"token punctuation\">(</span>el<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">toBeInstanceOf</span><span class=\"token punctuation\">(</span>HTMLElement<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre>\n<p>Happy DOM provides a lightweight browser environment, and the included scripts support:</p>\n<ul>\n<li>Watch mode for development: <code>npm test</code></li>\n<li>Single run for CI: <code>npm run test:run</code></li>\n<li>Interactive UI: <code>npm run test:ui</code></li>\n<li>Coverage reports: <code>npm run test:coverage</code></li>\n</ul>\n<h2 id=\"automated-publishing-with-oidc\" tabindex=\"-1\"><a class=\"header-anchor\" href=\"#automated-publishing-with-oidc\" aria-hidden=\"true\">#</a> Automated publishing with OIDC</h2>\n<p>The template is configured for secure automated publishing to npm using OpenID Connect (OIDC), which is more secure than long-lived tokens. After you manually publish the first version and configure OIDC on npm, create a GitHub release and the workflow handles publishing automatically.</p>\n<p>Manual publishing is still supported if you prefer that approach.</p>\n<h2 id=\"following-best-practices\" tabindex=\"-1\"><a class=\"header-anchor\" href=\"#following-best-practices\" aria-hidden=\"true\">#</a> Following best practices</h2>\n<p>The template bakes in best practices from the start:</p>\n<ul>\n<li>Shadow DOM with proper encapsulation</li>\n<li>Custom Elements v1 API</li>\n<li>Reflection of properties to attributes</li>\n<li>Lifecycle callbacks used appropriately</li>\n<li>Accessible patterns and ARIA support</li>\n<li>Progressive enhancement approach</li>\n</ul>\n<p>The included <a href=\"https://github.com/aarongustafson/web-component-starter/blob/main/WEB-COMPONENTS-BEST-PRACTICES.md\"><code>WEB-COMPONENTS-BEST-PRACTICES.md</code> document</a> explains the reasoning behind each pattern, making it a learning resource as well as a starter template.</p>\n<h2 id=\"why-i-built-this\" tabindex=\"-1\"><a class=\"header-anchor\" href=\"#why-i-built-this\" aria-hidden=\"true\">#</a> Why I built this</h2>\n<p>After creating components like <a href=\"https://github.com/aarongustafson/form-obfuscator\">form-obfuscator</a>, <a href=\"https://github.com/aarongustafson/tabbed-interface\">tabbed-interface</a>, and several others, I found myself copying and adapting the same project structure each time. This template captures those patterns so I — and now you — can start building components faster.</p>\n<p>If you build something with it, I’d love to hear about it!</p>\n","social_text":"Start building web components the right way with this production-ready template.","url":"https://www.aaron-gustafson.com/notebook/a-web-component-starter-template/","tags":["web components","JavaScript","open source","developer tools","best practices"],"date_published":"2026-01-02T00:06:37Z"},{"id":"https://www.aaron-gustafson.com/notebook/be-a-good-localstorage-neighbor/","title":"✍🏻 Be a good localStorage neighbor","summary":"Most JavaScript developers are keenly aware of what they add to the global object and do their best to namespace their work or sequester it in closures . Namespacing and closures reduce the likelihood that necessary functions and…","content_html":"<p>Most JavaScript developers are keenly aware of what they add to the global object and do their best to <a href=\"http://www.dustindiaz.com/namespace-your-javascript/\">namespace their work</a> or <a href=\"http://robertnyman.com/2008/10/09/explaining-javascript-scope-and-closures/\">sequester it in closures</a>. Namespacing and closures reduce the likelihood that necessary functions and variables will be accidentally overwritten, causing errors to be thrown and interfaces to break. Unfortunately, <a href=\"http://dev.w3.org/html5/webstorage/#the-localstorage-attribute\">the <code class=\"js\">localStorage</code> API</a> (available in most modern browsers) doesn’t inherently support creating isolated caches for each script because the cache is site-specific and consists simply of key-value pairs. <a href=\"http://msdn.microsoft.com/en-us/library/ms531424(VS.85).aspx\">Internet Explorer’s <code class=\"js\">userData</code> behavior</a> (which is available all the way back to IE5) does support sequestering the cache to a degree because you need to provide a name for it, but the API doesn’t make a whole lot of sense and isn’t at all equivalent to <code class=\"js\">localStorage</code>.</p>\n<p>Using the native APIs, it’s quite easy to accidentally overwrite an existing key in the cache. Beyond that, a simple call to <code class=\"js\">localStorage.clear()</code> will wipe out not only your own data, but anything else stored in the local cache. It’s not good.</p>\n<p>While working on <a href=\"http://eCSStender.org\">eCSStender</a>’s implementation of client-side caching, I came to realize the problems with the current state of things and sought to address them by implementing faux namespacing via prefixed keys. I’ve since copied that code out of eCSStender and created a small library named <a href=\"http://github.com/easy-designs/Squirrel.js\">Squirrel.js</a> that not only evens out the differences between <code class=\"js\">localStorage</code> and <code class=\"js\">userData</code>, but also makes it easier to manage your client-side data store in a manner unlikely to cause issues with other scripts also using client-side caching.</p>\n<p>Here is a quick rundown of how Squirrel.js works:</p>\n```js\n  // create a Squirrel instance\n  var $S = new Squirrel( 'scale-song' );\n<p>// write a value to the cache\n$S.write( ‘doe’, ‘ray’ );\n// read it back\n$S.read( ‘doe’ ); // ‘ray’</p>\n<p>// write a value to a sub-cache\n$S.write( ‘song’, ‘doe’, ‘a dear, a female dear’ );\n// read back the original value\n$S.read( ‘doe’ ); // ‘ray’\n// read back the sub-cached value\n$S.read( ‘song’, ‘doe’ ); // ‘a dear, a female dear’</p>\n<p>// removing a single property from the sub-cache\n$S.remove( ‘song’, ‘doe’ );\n// try to read the sub-cached value\n$S.read( ‘song’, ‘doe’ ); // null\n// read the root value\n$S.read( ‘doe’ ); // ‘ray’</p>\n<p>// add some more content to the sub-cache\n$S.write( ‘song’, ‘doe’, ‘a dear, a female dear’ );\n$S.write( ‘song’, ‘ray’, ‘a drop of golden sun’ );\n// clear the whole sub-cache\n$S.clear( ‘song’ );\n// check that it’s been cleared\n$S.read( ‘song’, ‘doe’ ); // null\n$S.read( ‘song’, ‘ray’ ); // null\n// check that the root value’s still instact\n$S.read( ‘doe’ ); // ‘ray’</p>\n<p>// remove a property form the main cache\n$S.remove( ‘doe’ );\n// check it’s value\n$S.read( ‘doe’ ); // null</p>\n<p>// write a bit more data in the root and in a sub-cache\n$S.write( ‘doe’, ‘ray’ );\n$S.write( ‘song’, ‘doe’, ‘a dear, a female dear’ );\n$S.write( ‘song’, ‘ray’, ‘a drop of golden sun’ );\n// clear the whole cache\n$S.clear();\n// check it’s all gone\n$S.read( ‘song’, ‘doe’ ); // null\n$S.read( ‘song’, ‘ray’ ); // null\n$S.read( ‘doe’ ); // null</p>\n<pre><code>&lt;p&gt;For more, check out &lt;a href=&quot;http://github.com/easy-designs/Squirrel.js&quot;&gt;the Github page&lt;/a&gt;. Feel free to let me know your thoughts on how easy it is to use and how it can be improved.&lt;/p&gt;\n</code></pre>\n","url":"https://www.aaron-gustafson.com/notebook/be-a-good-localstorage-neighbor/","tags":["JavaScript","best practices"],"date_published":"2010-08-02T12:17:28Z"},{"id":"https://www.aaron-gustafson.com/notebook/give-a-hoot/","title":"✍🏻 Give a hoot","summary":"As any competent JavaScript knows, it’s not cool to litter the global namespace with variables, functions, and the like. It’s far better to encapsulate your code in an object, a series of objects, or even a closure, exposing only what…","content_html":"<p>As any competent JavaScript knows, it’s not cool to litter the global namespace with variables, functions, and the like. It’s far better to encapsulate your code in an object, a series of objects, or even a closure, exposing only what you absolutely need to via the global namespace. This helps reduce the potential for collisions that will probably cause your site to break.</p>\n<p>Occasionally, however, even closures won’t help you trap a given variable. Case in point:</p>\n```js\n  (function(){\n   var a = b = 0;\n  })();\n```\n<p>If you’re familiar with languages like PHP, you might think this simple closure creates two variables with the same value, but you’d be wrong. It creates a local variable, <code class=\"js\">a</code> and a global variable <code class=\"js\">b</code>, both of which have their value set to 0.</p>\n```php\n  <?php\n<p>function example()\n{\n$a = $b = 0;\n}</p>\n<p>?&gt;</p>\n<pre><code>&lt;p&gt;In exp:easy_gists this means of sharing the value assignment of variables is perfectly legit; the difference, however, is how JavaScript and PHP treat variable scope. By default, every variable declared in PHP is scoped to the function it is called within. Global variables only come into play when you use the &lt;code class=&quot;php&quot;&gt;global&lt;/code&gt; declaration or the &lt;code class=&quot;php&quot;&gt;$_GLOBALS&lt;/code&gt; array. In JavaScript, by contrast, any variables not instantiated with a &lt;code class=&quot;js&quot;&gt;var&lt;/code&gt; are added to the global namespace. Hence the namespace pollution in the above example.&lt;/p&gt;\n&lt;p&gt;Revisiting the closure, it’s best to rewrite it in one of two ways to maintain the variable scope:&lt;/p&gt;\n```js\n  (function(){\n   var a = 0, b = 0;\n  })();\n</code></pre>\n<p>or</p>\n```js\n  (function(){\n   var a = 0, b = a;\n  })();\n```\n<p>Which solution will work best is dependent solely on context. If you’re minifying the code and the value being assigned is anything more than a single character, the latter is probably the way to go.</p>\n<p>To help you discover and mitigate pollution in your own scripts (or to help you see what additions your standard JavaScript libraries are making to the global namespace), I’ve created a little script called <a href=\"http://github.com/easy-designs/EmissionsTest.js\">EmissionsTest.js</a>. It’s pretty easy to use, you simply include it as the first script on your page (preferably in the <code class=\"html\">head</code> of your document) and it does the rest. It will attempt to report its findings to the console (if your browser has one) or it will create a floating notice at the top of the page.</p>\n<p>You won’t want to include this script on a production site and it’s still pretty basic, but it could be very useful for tracking down any accidental emissions in your script.</p>\n","url":"https://www.aaron-gustafson.com/notebook/give-a-hoot/","tags":["JavaScript","best practices"],"date_published":"2010-07-19T19:06:57Z"},{"id":"https://www.aaron-gustafson.com/notebook/disneystorecouk-in-retrograde/","title":"✍🏻 DisneyStore.co.uk in retrograde","summary":"Andy’s beautiful standards-based design is gone, replaced by a table-based pile of (ahem) tag soup. Being the gentleman that he is, Andy has chosen to remain silent on the issue , but he has provided a forum for anyone else who wants to…","content_html":"<p>Andy’s <a href=\"http://www.malarkey.co.uk/Disney_Store_case_study.aspx\">beautiful standards-based design</a> is gone, replaced by a table-based pile of (ahem) tag soup. Being the gentleman that he is, <a href=\"http://www.stuffandnonsense.co.uk/archives/of_mice_and_men.html\">Andy has chosen to remain silent on the issue</a>, but he has provided <a href=\"http://www.stuffandnonsense.co.uk/archives/of_mice_and_men.html#author\">a forum for anyone else who wants to chime in</a>. Molly posted <a href=\"http://www.molly.com/2005/11/03/an-open-letter-to-disney-store-uk/\">an open letter to Disney</a> which I think sums the whole thing up quite well:</p>\n<blockquote cite=\"http://www.molly.com/2005/11/03/an-open-letter-to-disney-store-uk/\">\n<p>Shame on you Disney.</p>\n</blockquote>\n","url":"https://www.aaron-gustafson.com/notebook/disneystorecouk-in-retrograde/","tags":["web standards","best practices"],"date_published":"2005-11-03T11:08:29Z"},{"id":"https://www.aaron-gustafson.com/notebook/new-tutorial-westhost-on-rails/","title":"✍🏻 New tutorial: Westhost on Rails","summary":"I have been hosting on Westhost for a little over four years now with no major complaints and I also host the majority of my clients there. They offer a lot of options for very little money and are always adding new features to the…","content_html":"<p>I have been hosting on <a href=\"http://www.westhost.com\">Westhost</a> for a little over four years now with no major complaints and I also host the majority of my clients there. They offer a lot of options for very little money and are always adding new features to the accounts. Unfortunately, <a href=\"http://www.rubyonrails.org\">Ruby on Rails</a> is not one of them… yet.</p>\n<p>As I have begun working a bit more with Rails, I have been looking to get it installed on my server (as well as some of my clients’). One of the major half-truths of Rails evangelism is the ease of install, especially with a host running Apache 1.3. After doing a few rather painful installs myself for some new projects, I finally decided to document the process of installing Ruby on Rails at Westhost for my own knowledge and to help any others who may be trying to do the same. Hopefully, Westhost will soon start to offer Rails installs as part of their hosting packages, but, until then, I offer up <a href=\"http://www.easy-designs.net/articles/WesthostOnRails/\">this humble tutorial</a>.</p>\n","url":"https://www.aaron-gustafson.com/notebook/new-tutorial-westhost-on-rails/","tags":["web development","best practices"],"date_published":"2005-10-02T15:40:20Z"},{"id":"https://www.aaron-gustafson.com/notebook/death-to-bad-dom-implementations/","title":"✍🏻 Death to bad DOM Implementations","summary":"I just encountered a DOM implementation issue in IE which took about three hours to solve (and like a year off my life). The story goes like this:","content_html":"<p>I just encountered a DOM implementation issue in <abbr title=\"Internet Explorer\">IE</abbr> which took about three hours to solve (and like a year off my life). The story goes like this:</p>\n<p>I could not, for the life of me, figure out why a form submitted in Firefox was coming through perfectly while it was missing fields in <abbr title=\"Internet Explorer\">IE</abbr>. The <a href=\"http://www.bizhub.biz/info/\" title=\"Don't submit it unless you really want a PDF brochure or print sample\">form in question</a> has some normal fields and some dynamically generated ones (if JavaScript is enabled). The normal stuff was coming through fine, but I was getting no values for the dynamically generated fields when the form was submitted in <abbr title=\"Internet Explorer\">IE</abbr>. I checked the <code>$_REQUEST</code> variable (I am using <abbr title=\"Hypertext PreProcessor\">PHP</abbr>) to see what was coming through, just to be sure.</p>\n<p>I immediately figured it was missing <code>name</code> attributes, but I was using the proper syntax to create the input elements via the DOM (note: the actual <abbr title=\"JavaScript\">JS</abbr> is more generic than this)</p>\n```js\n  var inpt = document.createElement('input');\n  inpt.setAttribute('name', 'company');\n```\n<p>Indeed, when I looked at the page through the <a href=\"http://www.nils.org.au/ais/web/resources/toolbar/index.html\">Web Accessibility Toolbar</a>’s <a href=\"http://www.nils.org.au/ais/web/resources/toolbar/documentation_v2en.html#tools\">View Generated Source</a>, it was indeed missing the <code>name</code> attribute:</p>\n```html\n  <INPUT id=company maxLength=255>\n```\n<p>After about another hour or two of fruitless Google-ing, I finally typed in the magic phrase (<a href=\"http://www.google.com/search?q=setting+the+name+attribute+in+Internet+Explorer&amp;btnG=Search\">setting the name attribute in Internet Explorer</a>) and ended up on Bennett McElwee’s <a href=\"http://www.thunderguy.com/semicolon/2005/05/23/setting-the-name-attribute-in-internet-explorer/\">blog post of the same name</a>. Suddenly it was all clear and (as I expected) <abbr title=\"Internet Explorer\">IE</abbr>’s botched implementation of the DOM’s <code>createElement</code> function was to blame.</p>\n<p>According to the <a href=\"http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/name_2.asp\"><abbr title=\"Microsoft Developers Network\">MSDN</abbr><abbr> page on the <code>name</code> attribute</abbr></a> (linked and quoted in the blog entry):</p>\n<blockquote cite=\"http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/name_2.asp\">\n<p>The NAME attribute cannot be set at run time on elements dynamically created with the createElement method. To create an element with a name attribute, include the attribute and value when using the createElement method.</p>\n</blockquote>\n<p>It continued with the following example:</p>\n<blockquote cite=\"http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/name_2.asp\">\n```js\n  var oAnchor = document.createElement(\"<A NAME='AnchorName'></A>\");\n```</blockquote>\n<p>The script “solution” Bennett posted was somewhat of a red herring, however, as Firefox would actually execute the <code>createElement</code> intended for <abbr title=\"Internet Explorer\">IE</abbr> and end up with an element named “&lt;input name=”company” /&gt;” which would be rendered on the page as</p>\n```html\n  <<input name=\"company\" /> id=\"company\" maxlength=\"255\" />\n```\n<p>Perhaps you can see why this would be problematic.</p>\n<p>I augmented Bennett’s script slightly and renamed the function <code>createElementWithName</code> so I wouldn’t have to use it on every element I created in the script:</p>\n```js\n  function createElementWithName(type, name) {\n   var element;\n   // First try the IE way; if this fails then use the standard way\n   if (document.all) {\n   element =\n   document.createElement('< '+type+' name=\"'+name+'\" />');\n   } else {\n   element = document.createElement(type);\n   element.setAttribute('name', name);\n   }\n   return element;\n  }\n```\n<p>I am not a super fan of the reference to <code>document.all</code> as it feels so much like browser sniffing. I am up for suggestions to improve the function if you have any ideas.</p>\n<p>Anyway, I am posting this to hopefully save someone else from the major headache I had today.</p>\n","url":"https://www.aaron-gustafson.com/notebook/death-to-bad-dom-implementations/","tags":["JavaScript","web development","best practices"],"date_published":"2005-09-02T19:10:52Z"}]}