Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Original DOM element:
- // <div id="item" data-tags="popcorn,chickens"></div>
- // SET (for eg: based on an ajax response):
- // The first call (with .attr) updates the DOM element only:
- $item.attr('data-tags',response.tag); // "popcorn,chickens"
- $item.attr('data-tags'); // "popcorn,chickens,dandelions"
- // <div id="item" data-tag="popcorn,chickens,dandelions"></div>
- $item.data('tags',response.tag); // [popcorn,chickens]
- // This call references the $.data object stored by jQuery independently of the actual data-attr:
- $item.data('tags',response.tag); // [popcorn,chickens,dandelions]
- // (A 'get' call to $item.attr('data-tags') would still yield "popcorn,chickens" if we
- // had not set it using .attr above). So need to do both.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement