Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
How to convert Div data into json format using jquery

This is my html code. I want this div id "con" will be call when export button click then it show json data in console.

if anyone know please help

<html>
  <div id ="con">
    <div>Name : P</div>
    <div>Age : 20</div>
  </div>
  <button type="submit" onclick="append()">Export</button>
</html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can try the following method, I've added class attribute to your button:

$('.conSubmit').on('click', function() {
  var JSONObj = {};
  var divArr = $('#con div');

  $.each(divArr, function(index, val) {
    var data = val.innerText;
    var dataArray = data.split(':');
    index == 0 ? JSONObj.name = dataArray[1].trim() :
      JSONObj.Age = dataArray[1].trim();
  })
  console.log(JSONObj);

})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="con">
  <div>Name : P</div>
  <div>Age : 20</div>
</div>
<button class="conSubmit" type="submit">Export</button>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!