[Javascript] Dollar function for name=

Scott Reynen scott at randomchaos.com
Tue Jun 1 23:38:57 CDT 2010


On Jun 1, 2010, at 3:07 PM, Terry Riegel wrote:

> I want to be able to do something like...
>
> $name(n).value="sausage";
>
> In the case of a radio button it would be to set the radio whose  
> name is pizza and whose value is sausage to selected
>
> I will have to think through how this may/may not work. It is really  
> something specific to my thinking and for me to be able to create a  
> convenience function to let me address elements by their name  
> instead of having to create an ID for all of them.
>
> So in the case of an input I am thinking in terms of an "pseudo"  
> object/elment that will let me deal with all the radio buttons as a  
> single object/element.


I'm not generally one to point to frameworks when the question is  
about JavaScript, but your phrasing just screams framework.  Pseudo- 
elements to refer to multiple elements is exactly what JavaScript  
frameworks provide.  Here's how you'd do this in jQuery, for example:

$('[name=n]').val('sausage');

Peace,
Scott



More information about the Javascript mailing list