Q:

how to show only strings matching the last line of an textarea

Why this doesn't work?
txtags is an textarea
el should be content of last line inside txtags
poptag are divs.
$('.txtags').keyup(function (event) {
    var el = $(this).val().split("\n").pop();
    el = el.trim();
    console.log(el);  // this works
    $('.poptag').hide();
    $('.poptag').each(function(){
        if ($(this).text().indexOf(el) > -1) {
            $(this).show();
        }
    });
});

For example, I type abc and expect poptag with text abcx should be shown, but - it is not.

A:

The above code should work as this is checking correctly for the last line in textarea with the content of poptag

$('.txtags').keyup(function (event) {
    var el = $(this).val().split("\n").pop();
    el = el.trim();
    console.log(el);  // this works
    $('.poptag').hide();
    $('.poptag').each(function(){
        if ($(this).text().indexOf(el) > -1) {
            $(this).show();
        }
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class='txtags' ></textarea>
<div class='poptag'>this is me</div>
<div class='poptag'>apple ball </div>
<div class='poptag'>test for me</div>

