tags:

views:

29

answers:

2

I have a paragraph

<p id="one"/>

How can I write multiple lines of text to it. I want the output as

Line 1: input1
Line 2: input2

and so on where input1 is the text in the textbox.

I have tried this till now

$("#one").text("Line 1: " + $('#input1').text());
A: 

using <br/>?

$("#one").append("Line 1: " + $('#input1').text() + '<br/');
dfa
I got that but waht i wanted to ask is do I need to write append again to create a second line..there would a lot of code so is there an easy way to write multiple lines to a para.
A: 

If you want to show all inputs from the page or form in the order they appear:

var inputsValue = new Array();
$('input').each(function(i){
    inputsValue.push("Line " + (i+1) +": " + this.value);
});
$('#one').text(inputsValue.join("<br>"));

If you need only some inputs, mark them with a class and change $('input') to $('input.yourClassName').

If the order is not correct or there are holes in the number sequence of your ids you will need to change the code to extract the line number from the id.

Serhii