Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Would something like the below be what you're looking for?</p> <pre><code>&lt;!-- The container into which new hobbies will be inserted --&gt; &lt;ul id="hobbies"&gt; &lt;/ul&gt; &lt;form method="post" action=""&gt; &lt;!-- The form element the user will use to enter new labels. Note that the value of the for attribute of the label element matches the value of the id attribute of the input element --&gt; &lt;label for="hobby"&gt;Hobby:&lt;/label&gt;&lt;input type="text" id="hobby" /&gt;&lt;br /&gt; &lt;a id="add-hobby"&gt;Add Hobby&lt;/a&gt;&lt;br /&gt; &lt;input type="submit" id="saveStudentInfo" value="Save Details" /&gt; &lt;/form&gt; &lt;!-- $(handler) is a shorthand for $(document).ready(handler) see http://api.jquery.com/ready/ --&gt; &lt;script&gt; // would be placed in the HEAD, of course $(function (){ $('#add-hobby').click(function () { // Extract the input value var newHobbyText = $("#hobby").val(); // Create the list item to add var $newHobbyListItem = $("&lt;li&gt;&lt;/li&gt;").text(newHobbyText); // Create the delete link var $deleteLink = $("&lt;a&gt;&lt;/a&gt;").text("Delete").css("margin-left","5px"); // Register a delete handler (could be done as part of the above line) $deleteLink.click(function () { $newHobbyListItem.remove(); }); // Add the delete link to the list item $newHobbyListItem.append($deleteLink); // Finally, add the new item to the DOM $("#hobbies").append($newHobbyListItem); }); }); &lt;/script&gt; </code></pre> <p>Some notes on this implementation:</p> <ul> <li>I choose to use an unordered list over a table because it's less work and, arguably, more semantically correct.</li> <li>If you need to add an input element (or similar) to the form to track what hobbies have been added, that's simple enough to do (just follow the above pattern for building, appending, and removing elements; currently, the delete handler removes only the list item, but it could remove an input element as well. However, I wasn't sure how you planned to process this data, so it's not clear what the best information to place in the input elements would be.</li> <li>I removed a few HTML elements (e.g. the "Hobbies" heading, the cancel button) as they seemed to clutter the example. There's no reason they need to be omitted, but I was hoping to keep things concise.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload