$(selector).relCopy({options});
relCopy, short for rel copy, is a jQuery plugin that copies any DOM element, and its children, targeted by an action link's rel
tag. It is typically used in forms to copy the file upload fields for multiple file uploads. It can also be customized for any purpose that requires multiple copies of fields with limits and other features.
Call $(selector).relCopy(options)
on an element with a jQuery type selector defined in the attribute rel
tag. This defines the DOM element to copy.
In the example below, .phone
in rel=".phone"
is the selector jQuery will use to search the DOM and copy. Note: This can be any jQuery selector like #phone
.
$('a.copy').relCopy({limit: 5}); // <a href="example.com" class="copy" rel=".phone">Copy Phone</a>
Arguments | Type | Description |
---|---|---|
excludeSelector | string | A jQuery selector used to exclude an element and its children. |
limit | integer | The number of allowed copies, including original element. Default: 0 is unlimited. |
append | string | HTML to attach at the end of each copy. Great for an HTML "remove link." |
copyClass | string | A class to attach to each copy. |
clearInputs | boolean | Option to clear each copies text input fields or textarea. |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="jquery/relCopy.jquery.js"></script>
$().relCopy()
on elements when DOM is ready<script> $(function(){ $('a.copy').relCopy(); }); </script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Rel Copy Example</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery/relCopy.jquery.js"></script>
<script>
$(function(){
$('a.copy').relCopy();
});
</script>
</head>
<body>
<p><a href="#" class="copy" rel=".phone">Copy Phone</a></p>
<p class="phone"><label>Phone Number: <input type="text" /></label></p>
</body>
</html>
var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().slideUp(function(){ $(this).remove() }); return false">remove</a>';
$('a.copy').relCopy({limit: 3, append: removeLink});
var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().remove(); return false">remove</a>';
$('a.copy').relCopy({limit: 5, append: removeLink});
clearInputs
.clearInputs
.append
option.