Bug Tracker

Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#4575 closed bug (duplicate)

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

Change History (2)

comment:1 in reply to:  description Changed 14 years ago by jfrank

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.

comment:2 Changed 14 years ago by dmethvin

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.

Note: See TracTickets for help on using tickets.