Skip to content

Commit

Permalink
Added in jQuery.nodeName() to simplify checking nodeName constantly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeresig committed Jan 22, 2007
1 parent d2f9022 commit 8e105ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/jquery/jquery.js
Expand Up @@ -1100,7 +1100,7 @@ jQuery.fn = jQuery.prototype = {
return this.each(function(){
var obj = this;

if ( table && this.nodeName.toUpperCase() == "TABLE" && a[0].nodeName.toUpperCase() == "TR" )
if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));

jQuery.each( a, function(){
Expand Down Expand Up @@ -1229,6 +1229,10 @@ jQuery.extend({
typeof fn[0] == "undefined" && /function/i.test( fn + "" );
},

nodeName: function( elem, name ) {
return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
},

/**
* A generic iterator function, which can be used to seemlessly
* iterate over both objects and arrays. This function is not the same
Expand Down Expand Up @@ -1451,7 +1455,7 @@ jQuery.extend({
tb = div.childNodes;

for ( var n = tb.length-1; n >= 0 ; --n )
if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length )
if ( jQuery.nodeName(tb[n], "tbody") && !tb[n].childNodes.length )
tb[n].parentNode.removeChild(tb[n]);

}
Expand Down Expand Up @@ -1510,7 +1514,7 @@ jQuery.extend({
if ( value != undefined ) elem[fix[name]] = value;
return elem[fix[name]];

} else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == "FORM" && (name == "action" || name == "method") )
} else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName(elem, "form") && (name == "action" || name == "method") )
return elem.getAttributeNode(name).nodeValue;

// IE elem.getAttribute passes even for style
Expand Down
10 changes: 5 additions & 5 deletions src/selector/selector.js
@@ -1,6 +1,6 @@
jQuery.extend({
expr: {
"": "m[2]=='*'||a.nodeName.toUpperCase()==m[2].toUpperCase()",
"": "m[2]=='*'||jQuery.nodeName(a,m[2])",
"#": "a.getAttribute('id')==m[2]",
":": {
// Position Checks
Expand Down Expand Up @@ -45,7 +45,7 @@ jQuery.extend({
submit: "a.type=='submit'",
image: "a.type=='image'",
reset: "a.type=='reset'",
button: 'a.type=="button"||a.nodeName.toUpperCase()=="BUTTON"',
button: 'a.type=="button"||jQuery.nodeName(a,"button")',
input: "/input|select|textarea|button/i.test(a.nodeName)"
},
".": "jQuery.className.has(a,m[2])",
Expand Down Expand Up @@ -155,7 +155,7 @@ jQuery.extend({
// Perform our own iteration and filter
jQuery.each( ret, function(){
for ( var c = this.firstChild; c; c = c.nextSibling )
if ( c.nodeType == 1 && ( c.nodeName.toUpperCase() == m[1].toUpperCase() || m[1] == "*" ) )
if ( c.nodeType == 1 && ( jQuery.nodeName(c, m[1]) || m[1] == "*" ) )
r.push( c );
});

Expand Down Expand Up @@ -227,7 +227,7 @@ jQuery.extend({
// Do a quick check for node name (where applicable) so
// that div#foo searches will be really fast
ret = r = oid &&
(!m[3] || oid.nodeName.toUpperCase() == m[3].toUpperCase()) ? [oid] : [];
(!m[3] || jQuery.nodeName(oid, m[3])) ? [oid] : [];

} else {
// Pre-compile a regular expression to handle class searches
Expand All @@ -242,7 +242,7 @@ jQuery.extend({
var tag = m[1] != "" || m[0] == "" ? "*" : m[2];

// Handle IE7 being really dumb about <object>s
if ( this.nodeName.toUpperCase() == "OBJECT" && tag == "*" )
if ( jQuery.nodeName(this, "object") && tag == "*" )
tag = "param";

jQuery.merge( r,
Expand Down

0 comments on commit 8e105ef

Please sign in to comment.