Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div>
- <form method="post">
- <button onclick="$(this).closest('form').data('target', $('#ide'))">#ide</button>
- <button onclick="$(this).closest('form').data('target', $(this).closest('form').parent('div').prev('h1'))">$(this).closest('form').parent('div').prev('h1')</button>
- </form>
- </div>
- <div id="ide"></div>
- $('button').on('click', function (e) {
- var form = $(this).closest('form');
- var target = $(form).data('target');
- $(target).html(Math.random());
- e.preventDefault();
- });
- <div class="asdasdsadsad">
- <button data-method="closest" data-target="div">asdsadsadsadsa</button>
- </div>
- $('button').click(function () {
- var method = $(this).data('method');
- var target = $(this).data('target');
- $(this)[method](target).css({border: '1px solid #f00'});
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement