how to pass class name to keyup event in jquery

21 Views Asked by At

I want pass input class name to keyup event, but onkeyup="filter(this)" also got error

how to pass it?

$('.dropdown-select ul').before('<div class="dd-search"><input id="txtSearchValue" autocomplete="off" onkeyup="filter()" class="dd - searchbox" type="text"></div>');
$('.dropdown-select ul').before('<div class="dd-search"><input id="txtSearchValue" autocomplete="off" onkeyup="filter('+this.classname+')" class="dd - searchbox" type="text"></div>');
1

There are 1 best solutions below

0
vijay pancholi On

To pass the class name of the input element to the filter function in jquery keyup event, you can use jquery event handling methods rather than inline event handlers.

$('.dropdown-select ul').before('<div class="dd-search"><input id="txtSearchValue" autocomplete="off" class="dd-searchbox" type="text"></div>');

// Attach keyup event handler using jQuery
$('.dd-searchbox').on('keyup', function() {
    var className = $(this).attr('class'); // Get the class name of the input element
    filter(className); // Call the filter function with the class name as an argument
});

function filter(className) {
    // Your filter function logic here
    console.log("filter with class name:", className);
}