2

I am just starting with jQuery, and am trying to make a function. I would appreciate help with syntax.

http://jsfiddle.net/e2s8besv/

<p>blink me<p>

<style>p {display:none;}</style>

<script>
    (function( $ ) {
        $.fn.blink= function(speed) {
            var speed = $(speed).val();
            $(this).fadeIn(speed).fadeOut(speed).blink(speed);
        };
    }( jQuery));

    $("p").blink(1500);
</script>      
1
  • There's a <blink> tag for that ? Commented Feb 18, 2015 at 18:18

1 Answer 1

2

You don't need to use val() there:

$.fn.blink= function(speed) {
    $(this).fadeIn(speed).fadeOut(speed).blink(speed);
};

jsFiddle

But I would suggest to return jQuery instance also. So you will be able to reach this element in future or work with elements collection, not first matched element only:

$.fn.blink= function(speed) {
    return this.each( function() {
        $(this).fadeIn(speed).fadeOut(speed).blink(speed);
    });
};

jsFiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.