3

I'm trying to use a jQuery selector that finds all input fields with a specific name:

$('input[name=Filter']).click(function() {
    // do something
});

This should match the following items:

<input type="radio" name="Filter" value="A" />
<input type="radio" name="Filter" value="B" />

This is working fine. The problem I am having is that my names are dynamically generated by ASP.net MVC and the names have a period:

<input type="radio" name="Parent.Filter" value="A" />
<input type="radio" name="Parent.Filter" value="B" />

I tried to write the following selector:

$('input[name=Parent.Filter]').click(function() {
});

I am getting the following error: Uncaught Syntax error, unrecognized expression: [name=Parent.Filter]

How can I write this expression so that it works properly?

2
  • 1
    not sure if will work but try... $('input[name="Parent.Filter"]') Commented Feb 3, 2012 at 17:40
  • Have you tried 'input[name*="Filter"]'? Commented Feb 3, 2012 at 17:42

4 Answers 4

11

Quotes are mandatory, and in this instance it won't work without them.

$('input[name="Parent.Filter"]').click(function() {
});

From the API reference:

value An attribute value. Quotes are mandatory.

Here's a jsFiddle that demonstrates this.

Sign up to request clarification or add additional context in comments.

Comments

2

This works, you just need "" around the name:

$('input[name="Parent.Filter"]').click(function() {
});

Comments

1

Based on my comment to the question I can confirm that this does work...

$('input[name="Parent.Filter"]').click(function() {
});

Working example here

Comments

0

Use $("input[name='Parent.Filter']")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.