<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aad Pouw</title>
    <description>The latest articles on DEV Community by Aad Pouw (@aadswebdesign).</description>
    <link>https://dev.to/aadswebdesign</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F391723%2F1edf38aa-adf0-4ec6-869c-f9f584161663.png</url>
      <title>DEV Community: Aad Pouw</title>
      <link>https://dev.to/aadswebdesign</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aadswebdesign"/>
    <language>en</language>
    <item>
      <title>Some js here for a change (getElemsByDataset)!</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Sun, 27 Sep 2026 08:58:19 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/some-js-here-for-a-change-getelemsbydataset-d1p</link>
      <guid>https://dev.to/aadswebdesign/some-js-here-for-a-change-getelemsbydataset-d1p</guid>
      <description>&lt;h3&gt;
  
  
  Explanation:
&lt;/h3&gt;

&lt;p&gt;As I'm working on the development&lt;br&gt;
of a contentEditable based editor,&lt;br&gt;
I make use of the &lt;em&gt;dataset&lt;/em&gt;&lt;br&gt;
attribute intensively.&lt;/p&gt;

&lt;p&gt;Mostly I work with the&lt;br&gt;
&lt;strong&gt;DOM&lt;/strong&gt; tree directly but there are situations that I have to collect the &lt;em&gt;elements&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;For that I use&lt;br&gt;
&lt;em&gt;document.getElementsByTagname (this wrapped in a method,called '&lt;/em&gt;&lt;em&gt;getTagNames()&lt;/em&gt;&lt;em&gt;')&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It's okay and I get things&lt;br&gt;
done with it. Just sometimes it would be more handy if could collect a bunch of elements with different tag names, at once!. Sure I can use &lt;strong&gt;document.getElementsByClassname&lt;/strong&gt; but that also has its &lt;em&gt;pitfalls&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Therefor I began&lt;br&gt;
to think, why is there not&lt;br&gt;
something like&lt;br&gt;
'&lt;strong&gt;*.getElementsByDatasetNameValue&lt;/strong&gt;'? &lt;br&gt;
Because then you can give a group of elements a related dataset &lt;em&gt;name/value&lt;/em&gt; and collect them with one call, regardless of their '&lt;em&gt;tagnames&lt;/em&gt;'.&lt;/p&gt;

&lt;p&gt;As it kept me busy, I gave it a closer look.&lt;br&gt;
I began with reading about those &lt;em&gt;built-inn &lt;strong&gt;HTML&lt;/strong&gt;&lt;/em&gt; methods and how they are built first. For this I had a look at &lt;em&gt;whatwg.org#concept-getelementsbytagname / 4.5. Interface Document&lt;/em&gt;. Interesting to get some idea of how they are built but that's it.&lt;/p&gt;

&lt;p&gt;Then I asked myself, can I create something like that with js and I gave it a try?&lt;/p&gt;

&lt;h3&gt;
  
  
  The steps:
&lt;/h3&gt;

&lt;h4&gt;
  
  
  One:
&lt;/h4&gt;

&lt;p&gt;I created a class and&lt;br&gt;
a related export function for it '&lt;em&gt;GetElemsByDataset \ getElemsByDataset&lt;/em&gt;' \&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"I have kept '&lt;em&gt;NameValue&lt;/em&gt;' left out of it because this is clear and long enough."&lt;/p&gt;

&lt;h4&gt;
  
  
  Two:
&lt;/h4&gt;

&lt;p&gt;☛ Find a way to&lt;br&gt;
collect the elements for it first and this I did by creating this method.&lt;/p&gt;

&lt;pre&gt;/*
 * @action: collecting the tags.
 * @notice: It is possible to omit a parent element
   but not recommended because that could become a huge list of elements.
 */
get_tag_names = async (...args) =&amp;gt; {
  const [prt_el = null, log = false] = args
  let el;
  if(prt_el !== null)
    el = prt_el.getElementsByTagName('*');
  else
    el = document.getElementsByTagName('*');
  if(log === true)
    console.log('getTagNames(*)',el);
  return el;
}
&lt;/pre&gt;

&lt;h4&gt;
  
  
  Three:
&lt;/h4&gt;

&lt;p&gt;☛ Creating from this obtained values a 'for of loop', and collect the elements based on '&lt;em&gt;dataset names and values&lt;/em&gt;' within the class constructor.&lt;/p&gt;

&lt;pre&gt;constructor(...args){
  const [prt_el,data_name, data_val,log = false] = args;
  this.#dn = data_name;
  this.#dv = data_val ?? null;
  this.#prt_el = prt_el ?? null;
  this.#get_tags = [];
  (async()=&amp;gt; {
    if(this.#prt_el !== null){
      /*
       * @action: collecting the tags.
       * @description: this method is using the '*' to collect all the available elements from the parent element and are placed in a 'for of'.
       */
       const tags = await this.get_tag_names(this.#prt_el,log);
       for(const tag of this.unique_array(tags)){
         /*
          * @action: collecting  the elements based on a dataset 'name' or 'name/value pair'.
          */
          if(tag.dataset[this.#dn] !== undefined){
            if(this.#dv === null){
              tag.dataset[this.#dn];
              this.#get_tags.push(tag);
           }else if(tag.dataset[this.#dn] === this.#dv){ 
             tag.dataset[this.#dn] = this.#dv;
             this.#get_tags.push(tag);
           }
        }
      }
      const gt = this.unique_array(this.#get_tags);
      if(log === true)
        console.log('elems: ', gt );
    }       
  })();
}
&lt;/pre&gt;

&lt;h3&gt;
  
  
  How to use:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;just copy/paste it, place it in your script folder and use 'import' to connect to it (how you do that is up to you).&lt;/li&gt;
&lt;li&gt;it accepts four arguments.

&lt;ul&gt;
&lt;li&gt;parent_el:
☛ This is the nearest element that holds the sub elements with the desired dataset names.
&lt;/li&gt;
&lt;li&gt;data_name:
☛ Here you pass the dataset name like this 'fooBar' but not 'data-foo-bar' or 'foo-bar'!&lt;/li&gt;
&lt;li&gt;data_val:
☛ Here you can pass a dataset value! This is optional.&lt;/li&gt;
&lt;li&gt;log:
☛ standard value is 'false', when set to true it shows the relevant data in your dev tools.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Example/Use Case:
&lt;/h3&gt;

&lt;p&gt;☛ This is a class of a new project that I just started last Wednessday. This class uses also some other methods but the focus here is getting the elements by dataset '&lt;em&gt;name/value&lt;/em&gt;'.&lt;/p&gt;

&lt;pre&gt;/*
 * @action: creates &amp;amp; collects objects for later use elsewhere. 
 * @description: 
*/
constructor(obj_args){
  const {get_prts} = obj_args;
  const create_obj = MH.createObjects;
  const remove_obj = MH.removeObjects;
  const ctb = MH.createTreeBlock;
  const gb = MH.getBoundings;
  //where I focus on.
  const gebd = MH.getElemsByDataset;
  (async()=&amp;gt; {
    const dom_data = await create_obj('dom_obj',{...obj_args});
    await remove_obj(['grant_data','get_prts'],dom_data);
    if(get_prts.length &amp;gt; 0){
      for(const prt_ctn of get_prts){
       //where the magic happens!
       this.layers = await gebd(prt_ctn,'topLayer');
       if(this.layers.length &amp;gt; 0){
         const layers = this.layers;
         for(const layer of layers){
          const prefs = layer.dataset.prefix;
          //another magical method but not the focus here!
          await ctb(gb,layer,dom_data,`${prefs}_ctn_data`,prefs,3,true);
          }
          await DE.dataTopLayer(dom_data);
          await DE.dataMainLayer(dom_data);
          await DE.dataBtmLayer(dom_data);
        }
      }
    }
  })();
console.table({'DTLS': obj_args});
}
&lt;/pre&gt;

&lt;h4&gt;
  
  
  This results in:
&lt;/h4&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;(3) ➜ top_ctn &lt;br&gt;
&amp;lt;section class="relative" data-top-layer="df-top-ctn" data-prefix="top"&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;(3) ➜ main_ctn &lt;br&gt;
&amp;lt;main class="relative" role="presentation" data-top-layer="df-main-ctn" data-prefix="main"&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;code&gt;(3) ➜ btm_ctn &lt;br&gt;
&amp;lt;section data-top-layer="df-bottom-ctn" data-prefix="btm"&amp;gt;&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The goal of this method!&lt;/strong&gt;&lt;/p&gt;

&lt;pre&gt;top_ctn_data
  Object { top_ctn: section.relative, top_ctn_dims: DOMRect }   
main_ctn_data
  Object { main_ctn: main.relative, main_ctn_dims: DOMRect }
btm_ctn_data
  Object { btm_ctn: section, btm_ctn_dims: DOMRect }
&lt;/pre&gt;

&lt;h4&gt;
  
  
  You will find it here:
&lt;/h4&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;  ☛ &lt;a href="https://codeberg.org/aadswebthings/js_snippets/src/branch/main/scripts/get_elems_by_dataset.js" rel="noopener noreferrer"&gt;getElemsByDataset:&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  That's it!
&lt;/h4&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Why I have ditched the QuerySelector</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Sat, 11 Apr 2026 15:14:38 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/why-i-have-ditched-the-queryselector-1km9</link>
      <guid>https://dev.to/aadswebdesign/why-i-have-ditched-the-queryselector-1km9</guid>
      <description>&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;em&gt;'document.querySelector()'&lt;/em&gt; has many downfalls.

&lt;ul&gt;
&lt;li&gt;There are many articles on the web to read more about it!&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;As I work the Javascript &lt;em&gt;OOP&lt;/em&gt; way, I don't need it.&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  What I do instead and what I want to share here is this:
&lt;/h3&gt;

&lt;p&gt;Connecting to the &lt;em&gt;DOM&lt;/em&gt; directly.&lt;br&gt;
What I do is making use of already available object keys in the dom tree:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;document.activeElement (in callbacks and aside of event.target)&lt;/li&gt;
&lt;li&gt;firstElementChild&lt;/li&gt;
&lt;li&gt;lastElementChild&lt;/li&gt;
&lt;li&gt;children

&lt;ul&gt;
&lt;li&gt;length&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;nextElementSibling&lt;/li&gt;
&lt;li&gt;parentElement &lt;/li&gt;
&lt;li&gt;previousElementSibling&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Some Wisdom first:
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;If a parent element has just one child element.&lt;br&gt;
The values of &lt;em&gt;'firstElementChild'&lt;/em&gt; and &lt;em&gt;'lastElementChild'&lt;/em&gt; are equal.&lt;br&gt;
This means that &lt;em&gt;'lastElementChild'&lt;/em&gt; can be used too!&lt;br&gt;
☛ Bad practice, because if there is a new element to be  added at a later stage then things are broken.&lt;br&gt;
☛ Good practice is just to stick to &lt;em&gt;'firstElementChild'&lt;/em&gt; and leave &lt;em&gt;'lastElementChild'&lt;/em&gt; free for future use.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  How do I do that?
&lt;/h3&gt;

&lt;p&gt;It's about creating a central point to work from.&lt;br&gt;
Next is to create the objects out of them.&lt;br&gt;
For this I use a &lt;strong&gt;Map()&lt;/strong&gt; based function, called &lt;em&gt;'createObjects('obj_name',{})'&lt;/em&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Working it out:
&lt;/h3&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;First a reflection of my used html body structure:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&amp;lt;body&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;lt;div class='wrap container display-flex relative'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;section class='top relative'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;header class='relative'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;h3 class='relative'&amp;gt;example heading.&amp;lt;/h3&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/header&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/section&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;main class='relative'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;main-content class='workbench-ctn absolute'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;content-item class='wb-content relative display-flex'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dynamic content&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/content-item&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/main-content&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/main&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class='controls-ctn relative display-flex'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;aside class='sidebar-ctrl top relative display-flex'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Some other elements&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/aside&amp;gt;&amp;lt;!--sidebar-ctrl top--&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;aside class='open-close-block absolute'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;details id='toolbar_toggle' class='toggle toolbar relative' open&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;summary class='tb caret-up-uc relative' title='close toolbar'&amp;gt;&amp;lt;/summary&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/details&amp;gt;&amp;lt;!--toggle toolbar --&amp;gt;\&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;details id='menubar_toggle' class='toggle menubar relative' open&amp;gt;\&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;summary class='mb caret-left-uc relative' title='close menubar'&amp;gt;&amp;lt;/summary&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/details&amp;gt;&amp;lt;!-- toggle menubar --&amp;gt;&lt;br&gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/aside&amp;gt;&amp;lt;!--open-close-block --&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;aside class='sidebar-ctrl left relative display-flex'&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Other elements, dynamically added or used for callbacks&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/aside&amp;gt;&amp;lt;!--sidebar-ctrl left--&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&amp;lt;!-- controls-ctn --&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&amp;lt;!--div.wrap.container--&amp;gt;&lt;br&gt;
&amp;lt;/body&amp;gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then a file that I've created for this and is called &lt;em&gt;'get_dom_objects.js'&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There are two functions in this file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;getDomObjects()&lt;/strong&gt; (&lt;em&gt;for elements that have been created already&lt;/em&gt;) &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;getDomObjectsExtended(obj_args)&lt;/strong&gt; (&lt;em&gt;for elements that not have been created yet or elements that will be used at a later stage&lt;/em&gt;).
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;FT&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./functions.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getDomObjects&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;get_objects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;FT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createObjects&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;base_obj&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;
    &lt;span class="c1"&gt;//1. Obtaining the document.body&lt;/span&gt;
    &lt;span class="na"&gt;body_elem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   
      &lt;span class="c1"&gt;//other objects&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;  

  &lt;span class="c1"&gt;//2. Creating a const for further use.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;body_elem&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;//3. Obtaining the very first element after the body&lt;/span&gt;
  &lt;span class="cm"&gt;/**
   * It's easy, each body element has a firstElementChild
     and what that is?
   * As I'm using the given example here, 
     it is the _'div.container'_ element.
   */&lt;/span&gt;   
  &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wrap_ctn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstElementChild&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;//4. For this I create another const and also for &lt;/span&gt;
       &lt;span class="nx"&gt;further&lt;/span&gt; &lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;wrap_ctn&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;//5.&lt;/span&gt;
  &lt;span class="cm"&gt;/**
   * For getting the elements after the 'div.container',
     there are different ways to do that.
   * A. by using (not recommended!)
        'first/last' - 'ElementChild' &amp;amp; 
        'next/previous' -  'ElementSibling'.
   * B. by using (recommended) 'children.length'. 
   */&lt;/span&gt;
  &lt;span class="c1"&gt;// This way    &lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wrap_ctn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrap_children&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wrap_ctn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;top_ctn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wrap_children&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;main_elem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;wrap_children&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 

  &lt;span class="c1"&gt;//6. Creating consts from that.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;top_ctn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;main_elem&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;skipp&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;top_ctn&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;there&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;no&lt;/span&gt; &lt;span class="nx"&gt;need&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="c1"&gt;//7. Getting the elements inside the 'main_elem'&lt;/span&gt;
  &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;workbench_ctn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;main_elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstElementChild&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;controlls_ctn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;main_elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastElementChild&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now I have all the objects that I'm going to use in &lt;strong&gt;getDomObjectsExtended(obj_args)&lt;/strong&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getDomObjectsExtended&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj_args&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;body_elem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;wrap_ctn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;top_ctn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;main_elem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
         &lt;span class="nx"&gt;workbench_ctn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;controlls_ctn&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj_args&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;get_objects&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;FT&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createObjects&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ext_obj&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,{&lt;/span&gt;
    &lt;span class="c1"&gt;//1. Including the previously created objects    &lt;/span&gt;
    &lt;span class="nx"&gt;body_elem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;main_elem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;workbench_ctn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;controlls_ctn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;top_ctn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="c1"&gt;//2. Moving on with creating the objects!&lt;/span&gt;
  &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;wb_content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;workbench_ctn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstElementChild&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;controlls_ctn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;controls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;controlls_ctn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ctn_top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;open_close_block&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; 
    &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ctn_left&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;  
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;open_close_block&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toggles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//toolbar_toggle&lt;/span&gt;
    &lt;span class="na"&gt;tb_toggle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;open_close_block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstElementChild&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;//menubar_toggle &lt;/span&gt;
    &lt;span class="na"&gt;mb_toggle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;open_close_block&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastElementChild&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   
  &lt;span class="p"&gt;};&lt;/span&gt;        
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;get_objects&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Using those created objects:
&lt;/h4&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;In my &lt;em&gt;modules&lt;/em&gt; folder I have a file called &lt;strong&gt;modules_collect.js&lt;/strong&gt;, this contains one function &lt;strong&gt;modulesCollect()&lt;/strong&gt; and this is the file passed to my &lt;strong&gt;index.js&lt;/strong&gt;.\&lt;br&gt;
&amp;nbsp;&amp;nbsp;Within that file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I Collect all the imports from the sub folders.&lt;/li&gt;
&lt;li&gt;I'm  passing the objects to the &lt;em&gt;classes &amp;amp; functions&lt;/em&gt; within those sub folders.
#### The steps:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&amp;nbsp;&amp;nbsp;☛ In &lt;em&gt;'index.js'&lt;/em&gt; this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dom_elems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getDomObjects&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;modulesCollect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dom_elems&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&amp;nbsp;&amp;nbsp;☛  In &lt;em&gt;'modulesCollect'&lt;/em&gt; this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;modulesCollect&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj_args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj_args_ext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getDomObjectsExtended&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj_args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;//Passing obj_args_ext to the _classes_ and _functions_   &lt;/span&gt;
  &lt;span class="c1"&gt;//This could be as a whole or partially {destructed}  &lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What I use in my classes and functions for getting around?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;-.getElementsByClassName();

&lt;ul&gt;
&lt;li&gt;packeted in a custom function called &lt;em&gt;'getClasses()'&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;-.getElementsByTagName();

&lt;ul&gt;
&lt;li&gt;packeted in a custom function called &lt;em&gt;'getTagNames()'&lt;/em&gt;.
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Recently I have created a tooltip module, this module is very small.&lt;br&gt;
The module itself is up and running, what is left is creating a repo and some documentation for it.&lt;br&gt;
After that, I might create a &lt;em&gt;use case&lt;/em&gt; out of it and breaking things down?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Freedom for all:
&lt;/h3&gt;

&lt;p&gt;It's about sharing of how I do things.&lt;br&gt;
If you're happy with the way you work already, stick to it!&lt;/p&gt;

&lt;h4&gt;
  
  
  That's it.
&lt;/h4&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>opinion</category>
    </item>
    <item>
      <title>About the commandfor attribute.</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Sun, 22 Mar 2026 06:48:16 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/about-the-the-commandfor-attribute-5h45</link>
      <guid>https://dev.to/aadswebdesign/about-the-the-commandfor-attribute-5h45</guid>
      <description>&lt;h3&gt;
  
  
  What I want to share here is my experiences with the commandfor attribute.
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Short intro:
&lt;/h4&gt;

&lt;p&gt;I'm using it in my &lt;em&gt;&lt;strong&gt;moduleEditor&lt;/strong&gt;&lt;/em&gt;, where I'm working on.&lt;br&gt;
This is a fully &lt;strong&gt;OOP&lt;/strong&gt; based package and this means that all the &lt;strong&gt;HTML&lt;/strong&gt; elements are &lt;strong&gt;&lt;em&gt;programmatically&lt;/em&gt;&lt;/strong&gt; created and directly appended to the &lt;strong&gt;DOM&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Note:
&lt;/h4&gt;

&lt;p&gt;The development itself I do on my localhost and when the time is right I push an updated version to GitHub.&lt;/p&gt;

&lt;h4&gt;
  
  
  At present:
&lt;/h4&gt;

&lt;p&gt;I'm working on the development of my &lt;strong&gt;'ol/ul/li'&lt;/strong&gt; module and as this elements have a lot of options to be implemented.&lt;br&gt;
I'm working on a popupable toolbox to cater that.&lt;/p&gt;

&lt;p&gt;For this I'm making use of the &lt;em&gt;commandfor/command&lt;/em&gt; and  &lt;em&gt;popover&lt;/em&gt; attributes and the &lt;em&gt;command&lt;/em&gt; event.&lt;br&gt;
(This attributes here are passed to &lt;em&gt;button&lt;/em&gt; elements and a &lt;em&gt;target&lt;/em&gt; element.)&lt;/p&gt;

&lt;h4&gt;
  
  
  Explanation:
&lt;/h4&gt;

&lt;p&gt;For the creation of those buttons, I'm using a predefined function and in this function I have this rule:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;create_elem.commandForElement = command_for;&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This function I use within another function and this function contains this rule and creates another element.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;const toolbox_ctn = await SEE.toolboxCtnElem(toolbox_ctn_data);&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Next:
&lt;/h4&gt;

&lt;h5&gt;
  
  
  Here is what I experienced with the 'commandfor' attribute.
&lt;/h5&gt;

&lt;p&gt;First I passed &lt;em&gt;'elem_id'&lt;/em&gt; to the &lt;em&gt;create_elem.commandForElement&lt;/em&gt; rule, this gave an error, then I tried &lt;em&gt;'toolbox_ctn.id'&lt;/em&gt; and same story.&lt;/p&gt;

&lt;p&gt;What I got was this:&lt;br&gt;
&lt;em&gt;&lt;code&gt;Uncaught (in promise) TypeError: HTMLButtonElement.commandForElement setter: Value being assigned is not an object.&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Then when reading this message, I found the clue!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;'commandForElement'&lt;/em&gt; wants an &lt;strong&gt;object&lt;/strong&gt; being passed and not an id!&lt;/p&gt;

&lt;p&gt;In this case, what I had to pass here was &lt;em&gt;&lt;strong&gt;'toolbox_ctn'&lt;/strong&gt;&lt;/em&gt; because that is the object and solved the error.&lt;/p&gt;

&lt;p&gt;Also the &lt;em&gt;command_for&lt;/em&gt; attribute here stays empty.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;&amp;lt;button class="tbx-btn open relative" title="open" command="--open-toolbox" commandfor=""&amp;gt;+&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Alternatively:
&lt;/h4&gt;

&lt;p&gt;By using the following rule and instead of using &lt;em&gt;HTMLButtonElement.commandForElement&lt;/em&gt;, it is possible to use an &lt;em&gt;id&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;create_elem.setAttribute('commandfor',command_for);&lt;br&gt;
&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;!For within this package I prefer to stick to &lt;em&gt;HTMLButtonElement.commandForElement&lt;/em&gt; approach.&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Final word:
&lt;/h4&gt;

&lt;p&gt;When working with &lt;strong&gt;'HTMLButtonElement.commandForElement'&lt;/strong&gt; directly , it is an &lt;strong&gt;object&lt;/strong&gt; to be passed and not an &lt;strong&gt;id&lt;/strong&gt;!&lt;/p&gt;

&lt;h5&gt;
  
  
  That's it!
&lt;/h5&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>Why I prefer my own 'new Map()' based createObjects() function over 'new Map()' *.set().</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Sun, 25 Jan 2026 04:02:26 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/why-i-prefer-my-own-new-map-based-createobjects-function-over-new-map-set-224b</link>
      <guid>https://dev.to/aadswebdesign/why-i-prefer-my-own-new-map-based-createobjects-function-over-new-map-set-224b</guid>
      <description>&lt;p&gt;It's about, why I prefer this function over using 'new Map()' *.set()?&lt;br&gt;
First the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function createObjects(...args){
  const [map_object = null, map_entries = null] = args;
  if(map_object !== null &amp;amp;&amp;amp; map_entries !== null){
    const map = new Map([[map_object,map_entries]]);
    return map.get(map_object);
  }
  return null;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The advances of this function over using &lt;br&gt;
*.set('key1', 'value1');&lt;br&gt;
*.set('key2', 'value2');&lt;/p&gt;

&lt;p&gt;It can be used in the same way as using an ordinary object structure, doing the same thing as 'set' and is much shorter;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const foo = {key1: val1,key2: val2,};
  const bar = await FT.createObjects('bar_obj',{key1: val1,key2: val2,});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const foo = {};
  foo.key1 = val1;
  foo.key2 = val2;

  // 'FT' is a namespace and is from 'import * as FT from "...js"'!
  const bar = await FT.createObjects('bar_obj',{});
  bar.key1 = val1;
  bar.key2 = val2;

  bar['key1'] = val1;
  bar['key2'] = val2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Note:
&lt;/h4&gt;

&lt;p&gt;It's used in:&lt;br&gt;
My recently created '*ModuleEditer' and wherover more at a later stage.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;(*)Is part of my present GH page &lt;a href="https://aadswebdesign.github.io/" rel="noopener noreferrer"&gt;aadswebdesign&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My present rebuild of my github page and wherover more at a later stage too.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Also, I do this rebuild on my localhost and I will replace my present GH page, when the time is right for it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That's it!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>oop</category>
      <category>modular</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How I Process things?</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Sun, 31 Aug 2025 05:35:40 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/how-i-process-things-b9m</link>
      <guid>https://dev.to/aadswebdesign/how-i-process-things-b9m</guid>
      <description>&lt;h3&gt;
  
  
  Intro.
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Somehow this should have been my very first post here!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's about what over the years took me to of where I'm now with my coding skills and that is this. &lt;/p&gt;

&lt;h4&gt;
  
  
  1. Having an idea.
&lt;/h4&gt;

&lt;p&gt;That is where it begins with "like a feature for my github page!", then I begin to gather the needed info of how to create that feature. &lt;/p&gt;

&lt;h4&gt;
  
  
  2. Figuring out of how to do it.
&lt;/h4&gt;

&lt;p&gt;Figuring out of how to get my idea realised, trying to understand the concept and if needed lookup some examples or following a tut. &lt;/p&gt;

&lt;h4&gt;
  
  
  3. Start Coding.
&lt;/h4&gt;

&lt;p&gt;Finally &lt;q&gt;and the best way to get forward&lt;/q&gt;, I open the editor and start coding.&lt;br&gt;
Sure and depending on the complexity, making mistakes and doing things completely wrong.&lt;br&gt;&lt;br&gt;
Then learn from that and put persistence in place until I get it right. &lt;/p&gt;

&lt;p&gt;My credo always is this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;While and as long as the pc doesn't smoke, it is all okay to make mistakes 😉!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  4. Getting It Right.
&lt;/h4&gt;

&lt;p&gt;When I get it right, I move on and up to the next challence! &lt;/p&gt;

&lt;h3&gt;
  
  
  In a nutshell.
&lt;/h3&gt;

&lt;p&gt;Yes for me it's about being busy with it; learning, making mistakes, solving them and proceed to the next challence! &lt;/p&gt;

&lt;h3&gt;
  
  
  What I don't do!
&lt;/h3&gt;

&lt;p&gt;As I work with many concepts, there is no way that I remember them all and I don't even try it!&lt;/p&gt;

&lt;p&gt;There is no need for too, because there is MDN where I can find 99% of what I want too know!&lt;/p&gt;

&lt;h3&gt;
  
  
  What I also learned is this.
&lt;/h3&gt;

&lt;p&gt;There are moments on the road that I don't make any progress. When that occurs, I learned that having a break or looking the other way can do wonders. It helps to get a fresh new look on where I was working on! &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It happens that I solve things in seconds, where I previously spent hours on!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Trying things out.
&lt;/h3&gt;

&lt;p&gt;Trying things out, that is also what I do from time to time. Looking with a sharp eye to what I've created and or I can improve it, making it more KISS!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Yes, my goal is always to &lt;strong&gt;K&lt;/strong&gt;eep &lt;strong&gt;I&lt;/strong&gt;t &lt;strong&gt;S&lt;/strong&gt;hort and &lt;strong&gt;S&lt;/strong&gt;imple!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h5&gt;
  
  
  That's it.
&lt;/h5&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>learning</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How I load web-components</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Wed, 13 Aug 2025 09:19:07 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/how-i-load-web-components-183g</link>
      <guid>https://dev.to/aadswebdesign/how-i-load-web-components-183g</guid>
      <description>&lt;h3&gt;
  
  
  Intro.
&lt;/h3&gt;

&lt;p&gt;This is a follow up of my previous article &lt;q&gt;How I load my js&lt;/q&gt;.&lt;br&gt;
What I use as an example here are three simple webcomponents for my articles, extensions of the &lt;em&gt;HTMLDivElement&lt;/em&gt; and they are called (&lt;em&gt;&amp;lt;article-header&amp;gt;&lt;/em&gt;,&lt;em&gt;&amp;lt;article-main&amp;gt;&lt;/em&gt; and &lt;em&gt;&amp;lt;article-footer&amp;gt;&lt;/em&gt;). &lt;br&gt;
The aim of it is to make my articles more easy maintainable. Also,it is about of how I load them and not of how they are created.&lt;/p&gt;
&lt;h3&gt;
  
  
  How I do it?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Step 1 &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Somewhere in my folder structure I have a folder called &lt;q&gt;webComponents&lt;/q&gt;, within that I have a folder that contains the web components and a js file called &lt;q&gt;components_export.js&lt;/q&gt; and contains three exports like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export {articleHeaderDefine} from './path_to/article_header.js';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Step 2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Within my &lt;em&gt;index.js&lt;/em&gt; I have this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as WCP from './../path/to/components_export.js';
(async()=&amp;gt;{
  //note; in this case order doesn't matter but they should be invoked before anything else (on top)!
  await WCP.articleHeaderDefine();
  await WCP.articleMainDefine();
  await WCP.articleFooterDefine();
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation.
&lt;/h3&gt;

&lt;p&gt;And as stated in my previous article!&lt;br&gt;
The components are part of my &lt;em&gt;iife&lt;/em&gt; and this is a &lt;em&gt;fullfilled promise&lt;/em&gt; before it enters the &lt;em&gt;index.html&lt;/em&gt;. As a result of that, they are available in any order and at any time.&lt;/p&gt;

&lt;h3&gt;
  
  
  At last.
&lt;/h3&gt;

&lt;p&gt;For who this is?&lt;br&gt;
Those who are new to Javascript and want to learn more about it or just want to improve their skills as I constantly do too.&lt;/p&gt;

&lt;h4&gt;
  
  
  Some links here for more info.
&lt;/h4&gt;

&lt;p&gt;More about &lt;b&gt;IIFE&lt;/b&gt; at &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE" rel="noopener noreferrer"&gt;MDN(&lt;b&gt;IIFE&lt;/b&gt;)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More about &lt;b&gt;Javascript Modules&lt;/b&gt; at &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules" rel="noopener noreferrer"&gt;MDN(&lt;b&gt;JS Modules&lt;/b&gt;)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>module</category>
      <category>webdev</category>
      <category>css</category>
    </item>
    <item>
      <title>How I load my js?</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Mon, 11 Aug 2025 15:59:51 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/how-i-load-my-js-58j2</link>
      <guid>https://dev.to/aadswebdesign/how-i-load-my-js-58j2</guid>
      <description>&lt;h3&gt;
  
  
  Intro
&lt;/h3&gt;

&lt;p&gt;And after a long hiatus a new article about how I load my js.&lt;br&gt;
Then, recently I read an article about &lt;b&gt;Bulletproof web component loading&lt;/b&gt; and written by &lt;a href="https://gomakethings.com/bulletproof-web-component-loading/" rel="noopener noreferrer"&gt;Chris Go Make Things&lt;/a&gt; and someone who knows a lot more about javascript as me.                 It was about loading in the footer or in the head and using 'async/defer' &lt;/p&gt;

&lt;h3&gt;
  
  
  His Approach.
&lt;/h3&gt;

&lt;p&gt;His 'bulletproof' approach was by using &lt;em&gt;document.readyState&lt;/em&gt; and &lt;em&gt;DOMContentLoaded&lt;/em&gt; in his component classes.&lt;/p&gt;

&lt;h3&gt;
  
  
  My idea.
&lt;/h3&gt;

&lt;p&gt;This way might be bulletproof but complex and hard to maintain.&lt;br&gt;
The way I load my js is &lt;b&gt;Simple&lt;/b&gt;, &lt;b&gt;Bulletproof&lt;/b&gt;, &lt;b&gt;Fast&lt;/b&gt; and hardly needs any maintenance.&lt;/p&gt;

&lt;h3&gt;
  
  
  How I load my js?
&lt;/h3&gt;

&lt;p&gt;It's about loading js this way:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First step is to have an &lt;em&gt;index.js&lt;/em&gt; within the scripts folder and that contains the following.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//the imports on top
(async ()=&amp;gt;{
    /** 
      This is the place where all the js logic
      ends up but in the right order!
   */
})();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Second step, within your &lt;em&gt;index.html&lt;/em&gt; this:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script type='module' src='./path/to/scripts/index.js&amp;gt; &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;p&gt;At the first step, the code has been placed in an async (&lt;b&gt;I&lt;/b&gt;mmediately &lt;b&gt;I&lt;/b&gt;nvoked &lt;b&gt;F&lt;/b&gt;unction &lt;b&gt;E&lt;/b&gt;xpression)!&lt;br&gt;
That iife, is the final place where my js stuff ends up.&lt;br&gt;
This means that the promise is 100% fulfilled before it's passed to my &lt;em&gt;index.html&lt;/em&gt;.&lt;br&gt;
So what I get is a single substance that is complete and ready to use.&lt;br&gt;
Actually I rarely look at it, is no need for!&lt;/p&gt;

&lt;h3&gt;
  
  
  Note!
&lt;/h3&gt;

&lt;p&gt;Placing all in the right order within you &lt;em&gt;index.js&lt;/em&gt; is important!&lt;/p&gt;

&lt;h3&gt;
  
  
  Final.
&lt;/h3&gt;

&lt;p&gt;A Simple, Bulletproof and Fast  way of loading js!&lt;br&gt;
That's what I wanted to share!&lt;/p&gt;

&lt;p&gt;More about &lt;b&gt;IIFE&lt;/b&gt; at &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/IIFE" rel="noopener noreferrer"&gt;MDN(&lt;b&gt;IIFE&lt;/b&gt;)&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How I do: export/import?</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Sun, 12 Jan 2025 07:09:55 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/how-i-do-exportimport-4jk2</link>
      <guid>https://dev.to/aadswebdesign/how-i-do-exportimport-4jk2</guid>
      <description>&lt;p&gt;(&lt;em&gt;First, it's about of how I do things, no must(not) do this or that here!&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;I know there are many more ways to deal with javascript module export/import but this is of how I use it mostly!&lt;/p&gt;

&lt;h4&gt;
  
  
  EXPORT
&lt;/h4&gt;

&lt;p&gt;How I'm not doing it and why?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function foo(){}
function bar(){}
function other(){}
export {foo,bar,other}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this way, the file has to be maintained. As soon as there are functions changing/added or removed you have to spend time to update this list &lt;strong&gt;X&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How I do it then and why?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function foo(){}
export function bar(){}
export function other(){}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That might be clear, there is nothing to be maintained here &lt;strong&gt;V&lt;/strong&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  IMPORT
&lt;/h4&gt;

&lt;p&gt;It depends, if there are only one or two functions to be imported then I do it this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {foo,bar} from './path/to/let/say/functions.js';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it is more then that, same story as by export. It has to be maintained and there is no need for that. &lt;strong&gt;X&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How I do it then and why?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as FT from './path/to/let/say/functions.js';
//using it
FT.foo()
FT.bar()
FT.other()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This way, it is always up-to-date, and no maintenance required &lt;strong&gt;V&lt;/strong&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  &amp;nbsp;About wildcard/namespace
&lt;/h5&gt;

&lt;p&gt;I make sure it is in &lt;strong&gt;uppercase&lt;/strong&gt; ,&lt;strong&gt;short&lt;/strong&gt; and &lt;strong&gt;reflects&lt;/strong&gt; the imported filename&lt;/p&gt;

&lt;p&gt;So in this example FT is short and reflects the imported file &lt;strong&gt;F&lt;/strong&gt;unc-&lt;strong&gt;T&lt;/strong&gt;ions.js&lt;/p&gt;

&lt;p&gt;That's it about my use of javascript module export/import.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;My first post here and I have more in mind but for another time!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>learning</category>
      <category>coding</category>
    </item>
    <item>
      <title>My details/summary toggle idea!</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Fri, 26 Feb 2021 11:40:09 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/my-details-summary-toggle-idea-14em</link>
      <guid>https://dev.to/aadswebdesign/my-details-summary-toggle-idea-14em</guid>
      <description>&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/aadswebdesign/embed/GRNOMJW?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>codepen</category>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>setUrl() for WP endpoints</title>
      <dc:creator>Aad Pouw</dc:creator>
      <pubDate>Mon, 08 Feb 2021 19:22:05 +0000</pubDate>
      <link>https://dev.to/aadswebdesign/seturl-for-wp-endpoints-505a</link>
      <guid>https://dev.to/aadswebdesign/seturl-for-wp-endpoints-505a</guid>
      <description>&lt;h3&gt;
  
  
  What it is?
&lt;/h3&gt;

&lt;p&gt;A little js function to pass a wp endpoint url that updates itself if you upload from your local - to your live website!&lt;/p&gt;

&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;Lately I did that and forgot to update my local - to my live endpoint url. The result was that when navigating on my live I ended up on my local and what is not intended. Also, on chrome it invalidated my ssl certificate too!&lt;/p&gt;

&lt;h4&gt;
  
  
  The code:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;setUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;namespace&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;endpoint&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`https://&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/wp-json/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;enter a namespace and/or an endpoint&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;fetcher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;setUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my/namespace&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;my_endpoint&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),{&lt;/span&gt; &lt;span class="c1"&gt;//other stuff });&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Note:
&lt;/h4&gt;

&lt;p&gt;I'm using a js class here for this example and is out of scoop of this post.&lt;br&gt;
Also, feel free to use this little snippet, for sure without any warranty or reliability!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
