Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery selector: anchor elements by name

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.

like image 448
Jason S Avatar asked Jan 20 '12 22:01

Jason S


People also ask

Can you use CSS selectors in jQuery for selecting elements?

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.

What is the correct way of selecting the current element with jQuery selectors?

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.

Which is the correct jQuery selector to select all elements within the div?

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.

What is Colon in jQuery?

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.


1 Answers

You can do it like this:

$('a[name=foo]')

It's called a attribute equals selector.

like image 154
cambraca Avatar answered Oct 05 '22 23:10

cambraca