zadam zadam - 5 months ago 28
HTML Question

jQuery match multiple attributes

I have the following markup, and I want to make the

radio button checked.

<li><input type="radio" value="All" name="Foo"/>All</li>
<li><input type="radio" value="New" name="Foo"/>New</li>
<li><input type="radio" value="Removed" name="Foo"/>Removed</li>
<li><input type="radio" value="Updated" name="Foo"/>Updated</li>

I'd like to match via attribute, but I need to match on 2 attributes,

Something like this:

$("input[@name='Foo' @value='all']").attr('checked','checked');

Can someone show how this can be done?


The following HTML file shows how you can do this:

    <script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
    <script type="text/javascript">
      <li><input type="radio"  value="All"  name="Foo"  />All</li>
      <li><input type="radio"  value="New"  name="Foo"  />New</li>
      <li><input type="radio"  value="Removed"  name="Foo"  />Removed</li>
      <li><input type="radio"  value="Updated"  name="Foo"  />Updated</li>
    <a href="" >Click here</a>

When you click on the link, the desired radio button is selected. The important line is the one setting the checked attribute.