Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. <div>
  2. <form method="post">
  3. <button onclick="$(this).closest('form').data('target', $('#ide'))">#ide</button>
  4. <button onclick="$(this).closest('form').data('target', $(this).closest('form').parent('div').prev('h1'))">$(this).closest('form').parent('div').prev('h1')</button>
  5. </form>
  6. </div>
  7. <div id="ide"></div>
  8.  
  9. $('button').on('click', function (e) {
  10. var form = $(this).closest('form');
  11. var target = $(form).data('target');
  12. $(target).html(Math.random());
  13. e.preventDefault();
  14. });
  15.  
  16. <div class="asdasdsadsad">
  17. <button data-method="closest" data-target="div">asdsadsadsadsa</button>
  18. </div>
  19.  
  20. $('button').click(function () {
  21. var method = $(this).data('method');
  22. var target = $(this).data('target');
  23. $(this)[method](target).css({border: '1px solid #f00'});
  24. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement