Ticket #6379 (closed bug: worksforme)
Unable to use the attibute selector with a numeric attribute
| Reported by: | redlava | Owned by: | |
|---|---|---|---|
| Priority: | undecided | Milestone: | 1.4.3 |
| Component: | selector | Version: | 1.4.2 |
| Keywords: | attribute selector numeric | Cc: | |
| Blocking: | Blocked by: |
Description
I attempted to use the following selector but I was unable to select an object with a numeric attribute such as "1"
$('input[input.radio[value=1]]')
If I prefix the value attribute and the selector with a character it works correctly. Do numeric attributes need to be escaped in some way or am I missing something? I am aware that some attributes must not start with a number be I don't believe this is true for the input value attribute.
Change History
comment:2 Changed 3 years ago by dfens
it works properly
<html>
<head>
<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
<script>
$(document).ready(function() {
$('input[value=a]').css('background','red');
$('input[value=1]').css('background','green');
});
</script>
</head>
<body>
<input value="a" type="text"/>
<input value="1" type="text"/>
</body>
</html>
comment:3 Changed 3 years ago by addyosmani
- Priority set to undecided
- Status changed from new to closed
- Resolution set to worksforme
It would appear that in your original example (as well as in the follow up from a few months ago) you were using incorrect selectors to try selecting both an input with a numeric value as well as an input (of type radio) with a numeric value.
In order to select a radio input element simply use input:radio and you'll be able to do what you're attempting. Similar to what dfens has previously posted, doing this effectively combined with the :radio selector should solve the problem:
input:radio[value=1] for example
Please see here for a Live test case http://jsfiddle.net/6ar5c/
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

My previous example was actually incorrect, it should have read:
$('input.radio[value=1]')