javascript - JQuery is(":focus") -
it seems reason, cannot perform:
$(".exampleclass")[0].is(":focus");
it tells me - typeerror: undefined not function. trying grab few elements jquery, scan through them, , find 1 focused (so can focus next element in array programmatically).
var fields = $(".textfield"); var selected = false; for(var j = 0; j < fields.length; j++){ var field = fields[j]; console.log(field); if(selected){ field.focus(); }else if(field.is(':focus') && !selected ){ selected = true; } }
it works fine until field.is(':focus') why won't work?
when index jquery object [ ]
operator, extract underlying component of list of matched elements. component dom node, , won't have .is()
method.
if coded like
$(".exampleclass").eq(0).is(":focus");
you'd working jquery object, , wouldn't have problem.
Comments
Post a Comment