I'm new to jQuery so this is probably simple, but...
If I have this HTML:
<a name="foo">Foo</a>
how can I select the anchor element by its name foo
? It doesn't have an id
property.
Projects In JavaScript & JQueryjQuery uses CSS selector to select elements using CSS. Let us see an example to return a style property on the first matched element. The css( name ) method returns a style property on the first matched element. name − The name of the property to access.
The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.
Tag Class: It represents a tag available with a specific class in the DOM. For example: $('real-class') selects all elements in the document that have a class of real-class.
jQuery provides some very powerful selection expressions using colon (:) syntax. Things like :first , :odd , and :even let you write code like: $('#content a:first') to get the first anchor within #content, or $('tr:odd') to get the odd numbered rows of a table.
You can do it like this:
$('a[name=foo]')
It's called a attribute equals selector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With