Using jquery data function we can tag any object to
the DOM elements.
<div id="main">
</div>
//user object
var user = { 'userId': 'abc123', 'userName':
'abc' };
//subject object
var subject = { 'subName': 'cs', 'subMarks':
100 };
//adding user object to div tag
$('#main').data('user', user);
//adding subject object to div tag
$('#main').data('subject', subject);
//it retrives the user and subject
object from div tag
var userandsubject = $('#main').data();
//it retrives the user object from
div tag
var user = $('#main').data('user');
//it retrives the subject object
from div tag
var subject = $('#main').data('subject');
Let me know, if you have any feedback. Mail me for source code. Enjoy reading my articles…
sekhartechblog@gmail.com
No comments:
Post a Comment