Suppose you have an html code like this.
<input type="button" id="btn-press" value="Submit!">
<div id="egText></div>
If now you want to add some text into this div,you need to attach an event handler and You should move var input-text = $('#input-text').val(); and the other variables inside the click event handler, so when you click the button you will get the latest values.
Here is the code:-
$(function(){
$('#btn-press').click(function(){
var input-text = $('#input-text').val();
var input-black = $('#input-black').val();
var input-white= $('#input-white').val();
$('#egText').append("<li>"+input-text+" "+input-black+" "+input-white+"</li>");
});
I have used $.append to insert the content that you want.
I hope this code will be helpful to you all.
0 Comment(s)