title: How to generate an element on the right side of the heading with jQuery/JavaScript?
body: <p>I need help with one of my projects. Shown here in a short code example what it is about.</p>
  <p>Imagine that we have two areas. These are marked with the class &quot;box&quot;. In both boxes are elements which each have a heading and a certain content. Let's limit our example to the relevant headings.</p>
  <p>Now I would like to add elements in the right box, which are positioned directly behind the text of the headings. However, it should be noted that this element should not be a pseudo-element, because on the one hand I have already used it in my project and certain functions are called that are not intended for pseudo-elements.</p>
  <p>How do I position an element directly behind the text of another element?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>generateNewItems();
  
  function generateNewItems() {
    let elements = $(".box#test div");
    
    for (let elem of elements) {
      let heading = $(elem).children("h3");
      
      let leftPos = 10; /* HOW? */
      
      let el = $("&lt;div&gt;").addClass("new-item").css({
          "left": leftPos,
        "top": -3
      });
      
      $(elem).append(el);
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.new-item {
    position:absolute;
    background:red;
    height:30px;
    width:30px;
  }
  
  .box {
    width:50%;
    background:lightblue;
    float:left;
  }
  
  .box &gt; div {
    position:relative;
  }
  
  .box &gt; div &gt; h3 {
    background:green;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="box"&gt;
    &lt;div&gt;
      &lt;h3&gt;test-one&lt;/h3&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;h3&gt;test-two&lt;/h3&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="box" id="test"&gt;
    &lt;div&gt;
      &lt;h3&gt;small-text&lt;/h3&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;h3&gt;long-sample-text&lt;/h3&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>