I want to add whole html element to data attribute so that on click I can set it to localstorage and can use it on next pages as well instead of doing the same stuff again on next page ...
Here is what I was doing...
Checking if img_src has a value or not
if false than set a div with letter X and some styling
if true set img tag with src and some width and height
var img_src="userpic.png"; //this value comes from db
if(img_src=="" || img_src==null){
var po_img = '<div class="class-groupPic bg-1">X</div>';
}
else{
var po_img = '<img src="'+element.student.photo+'" width="34" height="34"/>';
}
<div class="col" data-img="'+po_img+'" data-religion="Hindu" data-category="OBC"></div>
Jquery on click
$(".col").on('click',function(){
window.localStorage.setItem('img',$(this).data('img'));
window.localStorage.setItem('religion',$(this).data('religion'));
window.localStorage.setItem('category',$(this).data('category'));
});
But this adding html inside data attirbute results

This above image is my html page result