0

I am making a small web application that allows users to add sticky notes to a page by clicking the add button. The following is the html that makes up a sticky note.

<div class="sticky_note">
    <div class="title">
      <input type="text" name="title" placeholder="My Title"><span class="close">x</span>
    </div>
    <div class="content">
      <textarea name="note" placeholder="Type here..."></textarea>
    </div>
</div>

I am just a bit unsure how to add another sticky note everytime the user clicks add. Any help would be appreciated. Thanks!

4 Answers 4

1

You could generate an html element by pressing a button, for example:

var div = document.createElement('div');
div.id = 'window'; //you can assign property to your element.

var div2 = document.createElement('div');
div2.id = 'windowhead';
div.appendChild(div2);
document.body.appendChild(div);

this code append a div into another main container. I hope that this can be help.

Sign up to request clarification or add additional context in comments.

Comments

0

var stickyNote = $('.sticky_note')[0].outerHTML;
$('#addBtn').click(function(){
  $stickyNote = $(stickyNote);
  $stickyNote.appendTo($('.sticky_notes_container'))
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="sticky_notes_container">
<div class="sticky_note">
    <div class="title">
      <input type="text" name="title" placeholder="My Title"><span class="close">x</span>
    </div>
    <div class="content">
      <textarea name="note" placeholder="Type here..."></textarea>
    </div>
</div>
</div>
<button id=addBtn>Add</button>

2 Comments

Thanks for the solution. I was wondering if you could shed any light on why the css styles for the dynamically added element are not displaying. Thanks!
create a small working example with css you are referring and then elaborate on what problem you are facing
0

Assuming all this is inside a main container ,just keep that var code=<div class="sticky_note">...</div> code in a string and use

$("container").append(code);

Comments

0

You can easily create a new div.By using

document.createElement("div")

You can add text, classes..just look up w3school for more details..

Also i see your requirement, that clicking on button it will create a sticky note..

Element.cloneNode()

Might be helpful for you..where you make a div once with all the design and structure and use it again again..

http://www.w3schools.com/jsref/met_node_clonenode.asp

2 Comments

document.createElement('div')
By mistake d was captial didnt noticed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.