Reputation:
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?
Upvotes: 3
Views: 435
Reputation: 816334
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.
Upvotes: 6
Reputation: 30498
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]');
Upvotes: 4