JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" autofocus/>
<input type="text" autofocus="autofocus"/>
<input type="text" customattribute/>
<input type="text" customattribute="Tom"/>
<input type="text"/>
CSS
input {
display:block;
}
JavaScript
// In IE7, it seems like the 'has attribute' selector isn't working for 'autofocus'.
// should be 2 but returns 5 in IE7
$('body').append('<br/> $("input[autofocus]").length=' + $("input[autofocus]").length);
// returns 2 in IE7 (correct)
$('body').append('<br/> $("input[customattribute]").length=' + $("input[customattribute]").length);
// using the native getAttribute() function gives the same result.
var ele = $("input").filter(function() {
var attr = this.getAttribute("autofocus");
return attr || attr === "" || attr === "autofocus"
})
$('body').append('<br/> elements with autofocus attribute (using filter): ' + ele.length);