@@ -358,27 +358,29 @@ will be show next):
358358
359359..code-block ::javascript
360360
361- // Get the ul that holds the collection of tags
362- var collectionHolder= $ (' ul.tags' );
361+ var $collectionHolder;
363362
364363// setup an "add a tag" link
365364var $addTagLink= $ (' <a href="#" class="add_tag_link">Add a tag</a>' );
366365var $newLinkLi= $ (' <li></li>' ).append ($addTagLink);
367366
368367jQuery (document ).ready (function () {
368+ // Get the ul that holds the collection of tags
369+ $collectionHolder= $ (' ul.tags' );
370+
369371// add the "add a tag" anchor and li to the tags ul
370- collectionHolder .append ($newLinkLi);
372+ $ collectionHolder .append ($newLinkLi);
371373
372374// count the current form inputs we have (e.g. 2), use that as the new
373375// index when inserting a new item (e.g. 2)
374- collectionHolder .data (' index' ,collectionHolder .find (' :input' ).length );
376+ $ collectionHolder .data (' index' ,$ collectionHolder .find (' :input' ).length );
375377
376378$addTagLink .on (' click' ,function (e ) {
377379// prevent the link from creating a "#" on the URL
378380e .preventDefault ();
379381
380382// add a new tag form (see next code block)
381- addTagForm (collectionHolder, $newLinkLi);
383+ addTagForm ($ collectionHolder, $newLinkLi);
382384 });
383385 });
384386
@@ -393,22 +395,22 @@ one example:
393395
394396..code-block ::javascript
395397
396- function addTagForm (collectionHolder ,$newLinkLi ) {
398+ function addTagForm ($ collectionHolder ,$newLinkLi ) {
397399// Get the data-prototype explained earlier
398- var prototype= collectionHolder .data (' prototype' );
400+ var prototype= $ collectionHolder .data (' prototype' );
399401
400402// get the new index
401- var index= collectionHolder .data (' index' );
403+ var index= $ collectionHolder .data (' index' );
402404
403405// Replace '$$name$$' in the prototype's HTML to
404406// instead be a number based on how many items we have
405407var newForm= prototype .replace (/ \$\$ name\$\$ / g , index);
406408
407409// increase the index with one for the next item
408- collectionHolder .data (' index' , index+ 1 );
410+ $ collectionHolder .data (' index' , index+ 1 );
409411
410412// Display the form in the page in an li, before the "Add a tag" link li
411- var $newFormLi= $ (' <li></li>' ).append (newForm);
413+ var $newFormLi= $ (' <li></li>' ).append ($ newForm);
412414$newLinkLi .before ($newFormLi);
413415 }
414416