Search code examples
jqueryline-breaks

Jquery break line between data fields


I tried to break line between fields, but nothing i red on previous cases has worked for me : "
" "\n"

$(function() {
    var body = $(document.body);
    for (var i = 0; i `enter code here`< data.length; i++) {
        $('<div></div').text(data[i].name + " " + data[i].age + " \n" + data[i].email).appendTo(body);

    }
});

Solution

  • $('button').click(function(){
        $('input').each(function(){
            $(this).after('<br>');
        });
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <button>fix it up</button>


    Of course, another way is just to use CSS:

    CSS:

    input{display:block;}
    

    input {display:block;}
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <input type="text" />