I have some HTML code like this:
<input id="fieldname-1" name="field_name[value][1]" value="1" type="checkbox" />
<input id="fieldname-2" name="field_name[value][2]" value="2" type="checkbox" />
<input id="fieldname-3" name="field_name[value][3]" value="3" type="checkbox" />
I want to access this with jQuery like:
$('input[field_name]').change( function() { dosomething(); });
i can not add a class field to do this by calling $('.classname') because it is rendered by the cck module of Drupal and i don’t want to add this to the theme layer.
The best thing would be to let my module add a class for every field. but a quicker solution would be to know how to access these fields by jQuery
You could use the attribute equals selector to do an exact match on the
nameattribute.Or if you wanted all the
<input>elements that start withfield_name, you’d use the attribute starts with selector.This will select all
<input>elements where thenameattribute starts withfield_name.Additionally, you can use
:checkboxin the selector instead ofinputif they’re all checkboxes.Also, you could use the same approach but with the ID attribute if you wanted.