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>
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>