Reputation: 84
I am just starting with jQuery, and am trying to make a function. I would appreciate help with syntax.
<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>
Upvotes: 2
Views: 58
Reputation: 27765
You don't need to use val()
there:
$.fn.blink= function(speed) {
$(this).fadeIn(speed).fadeOut(speed).blink(speed);
};
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);
});
};
Upvotes: 2