tags:

views:

36

answers:

3

I know how to find an object by .classname and by elementname and i think by #idname but how do i find by the value of its name?

+4  A: 
$('elementname[name=foo]')

docs

cobbal
+4  A: 

You can search for an element by any of its attributes:

$('element[attr=val');

So, for a table with the name 'MyTable'

$('table[name=MyTable]');

Of course, that doesn't just extend to elements:

$('.MyClass[name=MyTable]');
James Wiseman
+3  A: 

You can find elements by the the value of an attribute with

$('element[attribute=value]')

where element is an arbitrary selector (HTML element, .classname, or #ID) and attribute can be any attribute that you put inside the tags, e.g. src for img elements or href for a elements or also name for form field elements.

For example

$('#ID')

could be rewritten as (assuming the element is a div):

$('div[id=ID]')

Of course the later usage is no improvement but maybe it illustrates how the attribute selector works.

Felix Kling