Testcase for jQuery 7485

Inconsistency [attr] vs attr()

by jitter

HTML

<a text="a attr">a text</a>
<p text="a attr">p text</p>
<select><option text="a attr">option text</option></select>

JavaScript

function log(msg) {
    //trim it to make the output readable
    msg = msg.replace(/\r|\n/g, " ");
    msg = msg.substr(0, Math.min(150, msg.length));
    $("<p />").text(msg).appendTo("body");
}

//save beforehand as we later add <p> tags
var $has = $("[text]"),
    $attr = $("*");

log("---");
$has.each(function(i, ele) {
    log("[attr] selector: " + ele.tagName + ": " + $(ele).attr("text"));
});

log("---");
$attr.each(function(i, ele) {
    var text = $(ele).attr("text");
    if (text != undefined) {
        log("check with attr(): " + ele.tagName + ": " + $(ele).attr("text"));
    }
});