jQuery each line in textarea

ngplayground

html

<textarea id="gps" name="gps"></textarea>
<button>Click</button>

jquery

$('button').click(function(){
    var arrayOfLines = $('#gps').val().split('\n');
    $.each(arrayOfLines, function(index, item) {
        $this = $(this);
        console.log($this);         
    });
});

I am trying to output each line individually so that I can use them later on but at the moment the above seems to split each line and then place each letter as an object

JSBin

Rory McCrossan

You are placing a string into a jQuery object. Just use the item instead:

$('button').click(function(){
    var arrayOfLines = $('#gps').val().split('\n');
    $.each(arrayOfLines, function(index, item) {
        console.log(item);
    });
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

jQuery Textarea - Remove spacing but add line breaks after each word

Max Length for Each Line in Textarea

Multiple line replace jQuery textarea

Line up input, select, textarea to each other

create if statement on each individual line of a textarea object

how to remove first character in each line of textarea

How to print each line in textarea with javascript?

How to insert text into specific line in textarea with jQuery?

Regex for new line not working in textarea jQuery

Keep line breaks with jQuery .text() in textarea

Enable New Line in Textarea - Jquery Append

Jquery: Focus last line on textarea on change

Textarea Limit words per line Jquery or Javascript

how to wrap each line inside a textarea by html tags?

Adding paragraph tags around each line in html textarea

Different background colors for each line in the textarea (or editable div?)

php read from textarea each line doesn't work why?

Django show list of strings in textarea, each string from new line

Get each line from textarea that contains links with PHP

Trim and edit each line of textarea while user is typing

jQuery post textarea wrap hard not show line break

Append line and labels depending on textarea values jQuery (Reduce repeatability)

Prevent new line but allow enter(submit) in textarea (jquery)

jQuery - Adding a line break when value is added to textarea

Remove every even line from textarea using jQuery

jQuery split textarea content into two textareas at a particular line number

jQuery send and display ajax result per line of textarea

Place cursor at the 2nd line of a textarea with jQuery/JavaScript

Wrap each line text to an element using JQuery