JSFiddle - React, Tailwind, and code Playground

HTML

<div>
<h2>test2</h2>
<span>asdf</span>
</div>
<h1>test</h1>

JavaScript

var $obj = $("a, .div[attr=1234]").next('.test');

function last_operation( $$ ) {
    var selector = $$.selector,
        selector_cmpr;
    
    console.log( selector );
    
    while ( ( selector_cmpr = remove_paren( selector ) ) != selector ) {
        selector = selector_cmpr;
    }
    
    var operations = selector.split('.'),
        is_find    = selector.replace(/, /, '').split(' ').length > 1,
        operation;
    
    console.log( selector );
    
    if ( is_find ) {
        operation = 'find';
    } else if ( operations.length > 1 ) {
        operation = operations[ operations.length - 1 ].replace(/PAREN/, '')
    } else {
        operation = 'unknown';
    }
    return operation;
    
    function remove_paren( str ) {
        var str_cmpr = str.replace(/\([^()]+\)/, 'PAREN');
        return str_cmpr;
    }
}

console.log( last_operation( $obj ) );