Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Loop & append Jquery

I have this array of objects

[
  {
    "id": "41796005",
    "name": " Manoj ",
    "phoneno": " xyz",
    "email": "xyz@gmail.com"
  },
  {
    "id": "160865953",
    "name": " Manisha Sajnani ",
    "phoneno": "xyz",
    "email": "xyz@gmail.com"
  }
]

This is the id div’s in the html page

<div class="tuple on" data-tuple-id="160865953" ></div>

so my question is that how can i append the id's div phoneno value if both matches

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

the div’s are in the no. of 40

sho how can we loop upon them & append that data to the id which is available in the array

>Solution :

Loop on data and div, compare id and append your data as html on div.

Example:

var data = [{
    "id": "41796005",
    "name": " Manoj ",
    "phoneno": " xyz",
    "email": "xyz@gmail.com"
  },
  {
    "id": "160865953",
    "name": " Manisha Sajnani ",
    "phoneno": "xyz",
    "email": "xyz@gmail.com"
  }
]
$('.tuple').each(function() {
  var divid = $(this).data("tuple-id");
  var _id = $(this);
  $.each(data, function(key, val) {
    if (divid == val.id) {
      _id.html(val.name + '---' + val.phoneno + '---'+ val.email)
    }
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="tuple on" data-tuple-id="160865953"></div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading