TransWikia.com

Can i show all variable results in a div in jQuery?

Stack Overflow Asked by Nippledisaster on December 5, 2021

With jQuery I want to get a some element ID names and I want to show them in a div separately.

In the snippet when input[type="radio"]s clicked I’m getting some element ID names based on a specific class name

How can i show all the results in a div?

    $( 'li input[type="radio"]' ).click(function() {
      var itemEls = $('li .colorclass');
      
      itemEls.map(function() {
        return {
          name: this.closest('[id]').id,
          value: $(this).val()
        }
      }).get().forEach(function(e, index) {
        var text = ''' + e.name + '': '' + e.value + '',';
        
         alert("I WANT TO ADD OR PASTE ALL THE RESULTS IN A DIV!" + text );

      });
      
    });
<!DOCTYPE html>
    <html>
    <head>
    <title>Page Title</title>

    </head>
    <body>

    <li id="color-blue">
      <span><input type="text" value="#000" class="colorclass" ></span>
    </li>
    <li id="color-idk-white">
      <span><input type="text" value="#fff" class="colorclass" ></span>
    </li>

    <li>
      <span><input type="radio" value="color_idk_white"></span>
    </li>
    <li>
      <span><input type="radio" value="color_idk_red"></span></li>

<div class="results"></div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    </body>
    </html>

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP