Jquery value retrieval from name tag

This is created for me by my perl script.

    print qq|
        \$('textarea[name=category$row[0]]').keydown(function(event)
         {
            \$("input[value=$row[0]]").attr('checked', true);
        });
    |;

Somewhere later, I have this, I want to re-extract the value of $ row [0], but I'm not sure how in jquery.

print qq|
<script>
    \$('#display_category').change(function() {
        var text = \$(this).val();

        \$('textarea[name^="category"]').each(function() {
            var foundvalue = \$(this).val();

            if (text == foundvalue)
            {
                alert("FOUND HERE " + foundvalue);

            }
        });
    });
</script>

|;

how can I re-select the category \ d + from the category and use it in my if condition?

+3
source share
1 answer
alert("category1234".match(/\d+/g)[0]);

So something like:

var num = $(this).attr('name').match(/\d+/g)[0];

or (I prefer this one):

var num = $(this).attr('name').replace(/[^\d]/g, '');

Demo: http://jsfiddle.net/karim79/8r8vs/3/

+5
source

Source: https://habr.com/ru/post/1779416/


All Articles