Skip to main content

Bug Tracker

Side navigation

#4575 closed bug (duplicate)

Opened April 22, 2009 03:32PM UTC

Closed August 09, 2009 01:59AM UTC

Last modified March 13, 2012 04:05PM UTC

Attribute selector doesn't work in IE7 in the circumstances

Reported by: estahn Owned by:
Priority: major Milestone: 1.4
Component: unfiled Version: 1.3.2
Keywords: Cc:
Blocked by: Blocking:
Description

One of our forms contains an input field with attribute "name" and attribute value "name". Forms that contains such input fields are not accessible via the selector engine.In the example below the form with that kind of input field is called "foo".

<html> 
<head> 
	<meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> 
</head> 
<body>
<form name="foo">
    <input type="text" name="name" value="form[name=foo]" />
</form>
<form name="foo2">
    <input type="text" name="name" value="form[name=foo2]" />
</form>

<form name="bar">
    <input type="text" name="name1" value="form[name=bar]" />
</form>
<input type="button" id="button" value = "Count" />
<div id="result"></div>
<script type="text/javascript">
    $(function() {
            $('#button').click(function(){
                $('#result').html(
                    'form : ' + $("form").length + "<br />" +
                    'form[name=foo] : ' + $("form[name='foo']").length + "<br />" + 
                    'form[name*=foo] : ' + $("form[name*='foo']").length + "<br />" + 
                    'form[name=bar] : ' + $("form[name='bar']").length + "<br />" +
                    'Workaround for "form[name=foo]" : ' + $("form").filter(function (index) {return $(this).attr('name') == 'foo';}).length 
                );
            })
    });
</script>
</body>
</html>

Results in IE7:

form : 3
form[name=foo] : 0
form[name*=foo] : 0
form[name=bar] : 1
Workaround for "foo" : 1

Results in Firefox 3.0.8:

form : 3
form[name=foo] : 1
form[name*=foo] : 0
form[name=bar] : 1
Workaround for "form[name=foo]" : 1
Attachments (0)
Change History (2)

Changed April 28, 2009 09:30PM UTC by jfrank comment:1

I ran into this issue today and have also confirmed that [attribute=value] does not work properly in IE.

With the following markup on the page...

<a href="" disabled="disabled">Test Link</a>

And the following JS...

test = $("a[disabled=disabled]");
alert(test.length);

IE alerts 0 and all other browsers alert 1.

Changed August 09, 2009 01:59AM UTC by dmethvin comment:2

resolution: → duplicate
status: newclosed

Duplicate of #3113 and not unique to jQuery; it's a DOM ambiguity. Avoid form element names such as "name", "length", "method", "action", etc.