Guest User

Untitled

a guest
Aug 16th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. HTML, custom element attribute, will work on all browsers?
  2. <div id="c" my-custom-attr="myValue" data-my-custom-attr="another-value">
  3. Content here
  4. </div>
  5.  
  6. <script type="text/javascript">
  7. $att1 = $('#c').attr('my-custom-attr');
  8. $att2 = $('#c').attr('data-my-custom-attr');
  9. </script>
  10.  
  11. <div id="c" data-my-custom-attr="another-value">
  12. Content here
  13. </div>
  14.  
  15. <script type="text/javascript">
  16. // Both produce the same output //
  17. console.log($('#c').attr('data-my-custom-attr'));
  18. console.log($('#c').data('my-custom-attr'));
  19. </script>
Add Comment
Please, Sign In to add comment