How to find find element by a class and specific name attribute?

I have multiple elements, like

<a href="#" name="0" class="myClass">Link 0</a>
<a href="#" name="1" class="myClass">Link 1</a>

I need a jQuery selector to get them, like

var myElement = $(.myClass).attr("name"="0");

or so..

Is that possible? Thanks!


Combine an attribute selector with the class selector:

Example Here

var $myElement = $('.myClass[name="0"]');

You were using the .attr() method which will either retrieve or set an element’s attribute, not select an element with a given attribute.

If you want to replace the 0 value with a variable, you could use the following:

Example Here

var number = 1,
$myElement = $('.myClass[name="' + number + '"]');