Search code examples
javascriptjqueryasp.net-mvcturbolinks

how to write jquery in body when using aspnetmvcturbolinks


I use aspnetmvcturbolinks in own project but, the jquery api that written in body is undefined. I move js files to head of layout .

$(document).on('keyup', 'input[name=keyword]', function () {
alert(this.attr("name"));
return false;
});

in this above code attr api is undefind!! what is solution? thanks.


Solution

  • It's because you have to pass this to jQuery to use jQuery methods...

    $(this).attr("name")
    

    ... else it looks into the object and returns undefined