Jump to content

add on input box after .click function?


swoonvin
 Share

Recommended Posts

<!doctype html><html lang="en"><head>  <meta charset="utf-8">  <title>To do list</title><link href='http://fonts.googleapis.com/css?family=Arvo:400,700,400italic,700italic' rel='stylesheet' type='text/css'>    <h1>To Do List</h1>    <style>button {margin-left: 30px;}h1 {font-family:'Arvo', slab-serif;  font-size: 25pt;   margin-left:30px;}  div {    display: none;    margin-left: 30px;    padding:5px; <!--to give space between each button-->  }  p {    font-weight: bold;    background-color: #fcd;  }</style>  <script src="https://code.jquery.com/jquery-1.10.2.js"></script></head><body> <button>Add</button><div>  <form>    <input type="text">    <button>Completed</button>  </form></div> <script>function add() {  $( "div" ).show( "fast" );}$( "button" ).click(function(){    $("div").append("$("input"); $( "form" ).submit(function( event ) {  if ( $( "input" ).val() === "yes" ) {    $( "p" ).show( 4000, function() {      $( this ).text( "Ok, DONE! (now showing)" );    });  }  $( "div" ).hide( "fast" );   // Prevent form submission  event.preventDefault();});</script> </body></html>
It's not javascript but I was hoping to get a feedback with the problem I have.
I'm trying to make it so that everytime I click "add" button, input box adds on.
I used .append but not working at all.
any suggestions??
Link to comment
Share on other sites

1) Learn how to PROPERLY use html, and where html elements can and cannot go, AND then validate.

 

2) Learn how to PROPERLY use Jquery, and how apply events correctly for especially jquery onload, and then onclick event.

 

This

 

$("div").append("$("input");

 

should be (I think trying to figure out what you are trying to do)

 

$("div").append("input");

 

but all this will do is find a input and append THAT input it to the bottom of div under the form

 

$("div").append('<input type="text">');

 

Will append a new input to div, but still outside form.

 

But! none of these will work correctly until you learn 1 and 2.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...